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! |
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!
|
|
|
|
Learn to enable users to both rate existing animations and to combine existing animations into new snippets. This is the third in a series of three tutorials that chronicle the building of a site that enables collaborative discussion and animation building using Domino and OpenLaszlo. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial version of WebSphere Business Modeler Advanced V6.1.1, IBM’s premier business process modeling and analysis tool for business users that offers process modeling, simulation, and analysis capabilities. IBM WebSphere Business Modeler helps you visualize, understand, and document business processes for continuous improvement. FREE! Go There Now!
|
|
|
|
Download a free trial version of IBM Rational Software Analyzer Developer Edition V7.0 to identify bug defects earlier in the software development cycle. Rational Software Analyzer is an extensible software development solution that reduces the expense of bug-fixes by enabling static analysis code reviews and bug identification very early in the development cycle. FREE! Go There Now!
|
|
|
|
As systems increase in complexity, communication between systems and software teams becomes more and more difficult. Now, there’s a way to improve product quality and communication.<br />Read the “Model Driven Systems Development” white paper to see how. Also included in this kit are more educational white papers, customer examples, tutorials, informative Webcasts, and best practices for designing, building and managing systems.<br /> FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference on December 4 at 1:00 pm ET to discuss how Rational Method Composer can help meet your compliance objectives. Get your questions answered! FREE! Go There Now!
|
|
|
|
Discover how Rational tools and best practices for testing can make your job easier. The new Rational Testing eKits provide you with valuable resources – including demos, webcasts, tutorials, and articles – that help you address your specific testing needs across the software lifecycle. Five new eKits are available covering the topics of Requirements and Test Management, Functional Testing, Performance Testing, Code Quality and Embedded Systems, and SOA and Web Services Testing. FREE! Go There Now!
|
|
|
|
Learn the basics of the IBM Customer Information Control System (CICS). With a hands-on exercise, learn how to get your first CICS application up and running on your desktop using TXSeries V6.1 for Windows. The tutorial shows you how to download and install a free trial version of TXSeries V6.1. FREE! Go There Now!
|
|
|
|
Attend this launch webcast with Scott Hebner, Vice President of IBM Rational Marketing and Strategy, where he will overview Rational’s new offerings and programs to help customers accelerate software innovation on System z. He will discuss how these solutions help organizations extend their core business processes toward modern architectures such as SOA and web technologies to deliver business improvements that stand the test of time. 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! |