Page 1 of 1

Database Driven Autocomplete

Posted: Thu Jan 17, 2008 2:05 pm
by icesolid
How are those auto complete boxes made where it gueses what you want by searching out a database and displaying back the result which like each letter you enter it narrows down what you are trying to search for?

How do you override auto complete so that even if the users browser has it turned on, you can disable it?

Re: Database Driven Autocomplete

Posted: Thu Jan 17, 2008 2:09 pm
by Oren
It seems like you are confusing between 2 different things :?

Re: Database Driven Autocomplete

Posted: Thu Jan 17, 2008 2:11 pm
by Jade
I'm not sure if you mean autocomplete as in search boxes on websites that use AJAX, or autocomplete like something google has. If it's a software the user has installed themselves I'm not sure there is a way to turn it off. If the website in question is using AJAX then I think if you turn your javascript off you may be able to turn off those features but then the site may not work. I dunno, I'm not all that familiar with AJAX and how it works but I do know its based off of Javascript.

Re: Database Driven Autocomplete

Posted: Thu Jan 17, 2008 2:17 pm
by icesolid
Im curious on how to do the AJAX auto complete.

Re: Database Driven Autocomplete

Posted: Thu Jan 17, 2008 2:31 pm
by Jade
Well I'm not an expert on AJAX but I know it has to do with opening a persistent connection to the server and then using XML and Javascript to run the scripts back and forth. I would suggest getting a AJAX book online. Then all you would do is setup the connection and have it run a query based on the input in the textbox. So for instance, as the user types it will automatically query for things that start with each keystroke. As what they enter gets longer or more specific then so would your query.

The query might look like:

Code: Select all

 
mysql_query("SELECT title FROM articles WHERE title LIKE '%$textbox_input%'")
or die ('cannot select articles matching that description ' . mysql_error());
 
Where $textbox_input is the value the user is entering into the field being picked up by Javascript and passed on to AJAX.

Re: Database Driven Autocomplete

Posted: Thu Jan 17, 2008 2:37 pm
by icesolid
Yeah I would be interested in a book to learn AJAX. It seems like a lot of people I talk to know of AJAX, but do not know how to code AJAX.

Interesting...

Re: Database Driven Autocomplete

Posted: Thu Jan 17, 2008 2:42 pm
by Jade
Lol. That's because AJAX can do basically what we do right now without needing to refresh the page like in PHP. Big advantage there. In this day an age everyone wants things fast, right now, at the click of a button. AJAX does that :D

I need to invest in an AJAX book myself.

Re: Database Driven Autocomplete

Posted: Thu Jan 17, 2008 2:57 pm
by Christopher
icesolid wrote:Im curious on how to do the AJAX auto complete.
"Ajax" calls are normal GET or POST calls. The difference is that they are done using the Javascript XMLHTTPRequest function rather than by having a link clicked or a form submitted. The result is that you can make calls to a URL and get resposne data, without having to reload the page. There is a huge amount of information on the web about it.

Re: Database Driven Autocomplete

Posted: Thu Jan 17, 2008 5:02 pm
by Kieran Huggins
in my pre-jQuery days I built a simple inline autocomplete method, but I would strongly encourage you to check out one of jQuery's many plugins for this behaviour.