Database Driven Autocomplete

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Database Driven Autocomplete

Post 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?
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Re: Database Driven Autocomplete

Post by Oren »

It seems like you are confusing between 2 different things :?
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Database Driven Autocomplete

Post 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.
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Re: Database Driven Autocomplete

Post by icesolid »

Im curious on how to do the AJAX auto complete.
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Database Driven Autocomplete

Post 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.
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Re: Database Driven Autocomplete

Post 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...
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Database Driven Autocomplete

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Database Driven Autocomplete

Post 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.
(#10850)
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: Database Driven Autocomplete

Post 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.
Post Reply