| | |||||||
| |||||||
| |||||||
|
|
|
|
|
|
|
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
More Search Code Articles |
| |
| |