![]() |
Auto Suggest Using PHP/MySQL & Ajax
I have come up with this code that gives you a nice google style suggest.
You can view a demo Here Downloads script.aculo.us 1.7.0 - This file is needed for this tutorial. Once you have downloaded the file unzip it and you should be presented with couple folders. We only need the files that are stored in src and lib folder. Create a folder under your website directory or where ever you are storing your website and call it javascript or something along them lines and put everything from the src folder and the one file thats in the lib folder Ready to start Once you have done that we can now start coding. Firstly we need to connect to them files we just put in a new folder, as they store the classes we need for the autosuggest to work. PHP Code:
Now we have included the files we needed. We can start constructing the page. We need to use DIV tags and input field to set up things. PHP Code:
PHP & MySQL Now we are going to be using PHP & MySQL to access a database and use the information found as the autosuggest information. Firstly of course we need to connect to the actual MySQL server and database. I would suggest creating a new file called config.php and put the following information in. PHP Code:
Now we can construct the code to place the information from the database into arrays. The following code may seem long winded or confusing, but i found it worked fine. PHP Code:
PHP Code:
Now thats pretty much it. From here it should work once you put it all together. I have supplied the full code below. PHP Code:
|
nice little example of an auto completer, cheers!
|
That was a really.. messy code for just an autocompleter :||
I have a much better script for this, but I'm not sure if it has the same useability, but it's nevertheless easier to understand! But, the tutorial was well written, and I'm sure alot of people will find this useful :) |
Ok, but needs better code.
|
How do you change the number of results displayed from the list?
|
hi,
i have used this code.it was really nice.but Iam getting problem with the database. iam using phpmyadmin.it is accepting only 708 records. after entering the 709 record it is entering in the database but autocomplete is not working for the whole. Please help me to solve this issue. Thanks. |
I don't think that this is technically 'Ajax' per say as there isnt anything asynchronous about it and all you are doing is using PHP to create a dynamic JavaScript array.
Sorry if i have missed something, i dont use prototype and scriptaculous |
i get data if i use this in the page..
Code:
$get = mysql_query("SELECT * FROM my_table")or die(mysql_error()); :-/ Code:
echo "<script type=\"text/javascript\">"; Code:
<script src="prototype.js" type="text/javascript"></script> Code:
<label for="bands_from_the_70s"></label> |
| All times are GMT. The time now is 03:07 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0