This is a modified version of The LLama's search script, which will query a MySQL Database and display the results. I modified by separating the script into two , and including not only the database connector, but instructions on getting the whole thing to work with little up front MySQL or PHP knowledge.
By : MatriX
#############################################
#<-------- CUT HERE FOR README -------->#
#############################################
#//////////////////////////////////////
#// MODIFIED 09 JUNE 01 - MatriX
#// Version 1.1
#//
#// Thanks to LLama for the original script! <The LLama (scripts@projectgis.org)> #// I have made the following modifications the original PHP to make it easier for newbies (like myself)
#// to get it working. The following has been modified:
#//
#// 1. Broke the original single posted script into two scripts - there was no "cut" to
#// separate the two, no big deal, but this will save a few minutes for a newbie
#// 2. Supplied generic database connector information. Hey, for PHP and MySQL newbies figuring
#// out how to enter the dabase information in a script can be a real bitch!
#// 3. Added a version number in case further modifications are made, 'cause this is a great script!
#//
#// -MatriX <matrix@digitalcyanide.net> #//
#///////////////////////////////////////
#############################################
Ramblings:
I came across this script at http://evilwalrus.com, a great source for PHP
scripts. Besides, they have a really cool logo, so check them out. Being
new at both MySQL and PHP, I was looking for a way to convert a flat text
based database of over 25,000 rows of 12 fields to SQL, and save some CPU
and response time. I decided on using SQL and PHP. This script worked almost
"out o the box" compared to all of the others I tried, and after minor tweaking was
able to query the database I created. The biggest challenge was writing the database
connector, which was probably the most time consuming part of the whole thing, so
I decided to put this fabulous script back out into the wild with some changes to make
it easier for others to use, and include a bit of documentation for the beginner. If you are
not a beginner, then you probably are not reading this.
Requirements:
MySQL
PHP
Database - no brainer
Web Server - again, no brainer
Suggested:
Linux B}
phpMyAdmin
Roxen or Apache
Usage:
OK, here we go. First off, you need to know the following in order to use this script:
Database Servers Name - The sever the database is located on
Database Users Name - The user name used to connect to the database
Database Users Password - The users password (sometimes NULL, but not a good idea)
Database Name - The name of the database you are going to be acessing
Database Table Name - The table inside the database you are going to query
There are two files that I have named find.php, and results.php. I chose these names as they
are intuitive. Find.php is the page that you will call in your browser (e.g. http://mydomain.net/find.php),
and enter the information you want to search for. When you click the Submit Query button, your results
will appear in the other script - results.php. See, I-N-T-U-I-T-I-V-E.
I have placed the variables in the script, where originally this was left out. All you need to do is fill in
the information and you are all set.
where:
The two place holders for your query are labeled as some_data_1, and some_data_2. These two
expressions with the underline in between (_) are where you need to enter the table data field, without the
underline is displayed in the browser exactly as you enter it, it is NOT part of the query, so you can change
this to what you want the user to see.
MODIFY find.php -
In the find.php script, locate "name= " This is where you need to enter the field you are searching in
for your data. You can and should have multiple fields, as in the example, and search for comparitive
matches. Just enter each of the fields on their own line
Some Data 1: <input type=text name=some_data_1 size=25 maxlength=25> Some Data 2: <input type=text name=some_data_2 size=25 maxlength=25> When you click on Submit Query, the data fields you entered will be queried to find a match for what you
entered on the web page, find.php. The query will be run from results.php which takes the information you
entered on find.php, searches the database, and displays the results. Here is where you need to enter
your database connect information.
MODIFY results.php
$db_host = 'localhost'; - The Database Server
$db_user = 'dbase_user'; - The Database Users Name
$db_pass = 'dbase_user_password; - The Database Users Password
$db_name = 'dbase_name'; - The Database name
$db_table = 'dbase_table_name'; - The Database Table you are querying
That should be it. Once you have finished entering your information, point your browser to find.php, enter
something in the fields, click Submit Query, and watch the results. Unless I have missed something in the script,
or you forgot to fill in some of the information correctly, you should have a working PHP-MySQP Database search
page. At least it was working on my server when I wrote this and zipped it up!
Lifeline:
Sorry, you cannot use your host as a lifeline. I have tried to document as well as I can, how to get this puppy working
for you, and as a matter of fact, I think the character count in this readme is larger than the actual scripts! If you still need
help, you can try some of the following links for information or assistance. If you make further modifications, please let me
know. Last but not least, thank The LLama (scripts@projectgis.org) for the original script.
EvilWalrus.com
php.net
mysql.com
End Transmission:
-MatriX <matrix@digitalcyanide.net> ####################################################
#<-------- CUT HERE - BELOW IS FIND.PHP -------->#
####################################################
// Begin find.php
<form method=post action="results.php"> Search For:
<p> Some Data 1: <input type=text name=some_data_1 size=25 maxlength=25> <p> Some Data 2: <input type=text name=some_data_2 size=25 maxlength=25> <p> <input type=submit> </form> // End find.php
#######################################################
#<-------- CUT HERE - BELOW IS RESULTS.PHP -------->#
#######################################################
// Begin results.php
<?
//MatriX Connector MOD
$db_host = 'dbase_server';
$db_user = 'dbase_user';
$db_pass = 'dbase_user_password';
$db_name = 'dbase_name';
$db_table = 'dbase_table_name';
$conn = mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db($db_name,$conn);
//MatriX connector MOD
// ---- END CONFIGURATIONS ------------------------------------------//
if ($some_data_1 == "")
{$some_data_1 = '%';}
if ($some_data_2 == "")
{$some_data_2 = '%';}
// $some_data_1 and $some_data_2 are the two column names I used. Change this to fit your database
$result = mysql_query ("SELECT * FROM dbase_name
WHERE some_data_1 LIKE '%$some_data_1%'
AND some_data_2 LIKE '%$some_data_2%'
",$conn);
if ($row = mysql_fetch_array($result)) {
do {
PRINT "Our database contains the following records: <br><br>";
PRINT "<b>Some Data 1: </b> ";
print $row["some_data_1"];
print (" ");
print ("<br>");
PRINT "<b>Some Data 2: </b> ";
print $row["some_data_2"];
print ("<p>");
print ("<p>");
} while($row = mysql_fetch_array($result));
} else {print "Sorry, no records were found!";}
?> // End results.php
// END OF FIND_V1.1
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More Search Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
Hold your calendar on January 30, 2008 for this free webcast on the new i5/OS. Rational's Enterprise Modernization products will be discussed at this webcast as they help to drive the application development environment for this new System i OS. <br />And learn how i5/OS will take you to the next step of efficient, resilient business processing. You will hear about the new i5/OS capabilities as it will be the most significant i5/OS release in years. If you cannot join the webcast on 1/30/08 you can still use this link to listen to the replay.<br /> FREE! Go There Now!
|
|
|
|
Learn field-tested SOA principles, methodology, technology and implementation from the global SOA market leader - in a new e-book by an IBM SOA expert. Written by IBM Certified SOA Solution Designer Bobby Woolf, "Exploring IBM SOA Technology & Practice" is the ultimate insider's guide to SOA - a PDF e-book packed cover to cover with IBM's specific advice on how to make your SOA implementation a success. FREE! Go There Now!
|
|
|
|
As businesses grow increasingly dependent upon Web applications to provide services to customers, employees and partners, these complex applications become more difficult to secure. Although traditional security solutions protect Internet infrastructure layers, they do not guard against HTTP and HTML attacks. Many organizations that conduct security testing still deploy applications that allow attackers to manipulate their logic and wreak havoc on their business. To mitigate this risk, development and delivery teams must address Web application security throughout the lifecycle, addressing the many layers detailed in this paper. FREE! Go There Now!
|
|
|
|
Attend this launch webcast with Scott Hebner, Vice President of IBM Rational Marketing and Strategy, for an overview of Rational’s new software offerings and resources to help modernize and accelerate software innovation on i on Power Systems – while ensuring past application investments are protected and continue to grow. Learn how these solutions are helping customers extend their core i5/OS solutions toward modern architectures such as SOA and web technologies to deliver business improvements that stand the test of time. FREE! Go There Now!
|
|
|
|
You probably have thousands of lines of COBOL code loaded with business intelligence and being used to run your business, along with an army of developers maintaining these applications. Learn how to prepare your applications and developers so you can keep that competitive edge and move to a service-oriented architecture with the IBM Rational Enterprise Modernization solutions. Replay is available for 9 months. FREE! Go There Now!
|
|
|
|
Learn how to implement a build management system that uses and extends your existing automation technologies. This tutorial shows, step-by-step, how to install and configure IBM Rational Build Forge to manage builds for Jakarta Tomcat from source code. FREE! Go There Now!
|
|
|
|
XML has become a common way of storing business data as flat files and many data server vendors including IBM have provided ways to store this data within relational database systems. Increasingly collections of XML files are accessed like databases using an xQuery and other XML standard mechanisms. Businesses find the need to combine the traditional tabular structured data with XML formatted data. In this webcast, you’ll learn about IBM’s WebSphere Federation Server technology, which provides users with the ability to integrate these two data formats. FREE! Go There Now!
|
|
|
|
Because access to government information continues to be an area of concern for many U.S. citizens with disabilities, the U.S. government enacted Section 508 of the Rehabilitation Act in 2001 to ensure that government agencies create accessible Web content, enabling all citizens to access the information they need. A fully accessible Web site makes Web content accessible to all individuals, including those with disabilities, who may be accessing Web content via a variety of user agents. Common user agents include standard Web browsers, text-only browsers, assistive devices and mobile devices such as cell phones or personal digital assistants (PDAs). FREE! Go There Now!
|
|
|
|
Get a free trial download of the latest version of IBM Rational Functional Tester V7.0.1. Rational Functional Tester is an automated functional and regression testing solution for QA teams concerned with the quality of their Java, Microsoft Visual Studio .NET, and Web-based applications. FREE! Go There Now!
|
|
|
|
The discipline of assembling and delivering software is maturing beyond standard developer-centric compile/test software builds. The end-to-end software development lifecycle is emerging as the new focus moves “Beyond the Build.” Join this on demand webcast to learn about methods for streamlining software delivery and key capabilities of the IBM Rational Build Forge framework for automating build and release management in environments of any size. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |