Sep 20
Ever heard of Google Suggest? I bet you did. Let me show you a simple Ajax-PHP-MySQL code based on suggest. This script will search a database and nest your result while and when you type.
I have used and modified the example shown on W3Schools.com.
What I have done, I left the Javascript file as it is and created a PHP file and instead of filling up the arrays I do the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | include("connection.php"); function suggest() { //get the q parameter from URL $q=addslashes($_GET["q"]); //connect to database makeConnection(); //make the query $select = "SELECT * FROM (table) WHERE (field) LIKE '".$q."%'"; $result = mysql_query($select) or die (mysql_error()); //do whatever you want to do with the result //disconnect from database disconnect(); } |