Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


PHP Combo Box (like in MS Access)

Posted on 2012-09-11
Medium Priority
Last Modified: 2012-09-11
I have a table that is going to grow considerably as the site grows with names of businesses.  I don't think I can realistically put this list of businesses in a <select></select> tag using PHP to grab the names from the database due to the size and potential number of records.  Is there such a thing as a "combo box" in PHP, which will recognize an entry once the user starts typing, without loading the entire database table into the list box first?  I'm just thinking that this could be too taxing on a shared server.  I hope I'm making sense!
Question by:ssailer

Assisted Solution

jhheider earned 501 total points
ID: 38388031
It wouldn't be in PHP, since that is all server-side dynamism. You'd need some AJAX to respond to the onChange= event of your text input, and send HTTP(S) queries back to a listener on the server. Basically, onChange= you'd want to call http://yourserver/lookup.php?q=$typed_date and do a SELECT * FROM table WHERE field LIKE '{$_GET['q']}%' LIMIT 30 or similar. While the listener is easy, you're probably going to have to look around for the AJAX or write some jQuery to do it.
LVL 84

Accepted Solution

Dave Baldwin earned 501 total points
ID: 38388073
You can use 'autosuggest' which brings up possibilities as you type.  http://code.google.com/p/ajax-auto-suggest/  It's really not that much load on a shared server since no one can type fast enough to cause a problem.

Author Comment

ID: 38388283
I need to be able to get the results from records in a database, and I didn't see any demos for the auto suggest.  Does this plug-in tap into a database table?

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

LVL 84

Expert Comment

by:Dave Baldwin
ID: 38388392
This line in autosuggest.js myAjax.makeRequest( url, meth, onSuccessFunc, onErrorFunc ); call 'test.php'.  'test.php' in the demo has a static array to get the info.  You could convert that into a database access.

There are many other demos available with PHP/MySQL code.  https://www.google.com/search?q=ajax+autosuggest+php+mysql
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 498 total points
ID: 38388763
Make a Google search for jquery autosuggest with php/mysql and see if the results look good.  They did to me, but I don't have time to test the solutions right now.  HTH, ~Ray

Author Comment

ID: 38388851
Actually, I found an extension at DMX Zone that does exactly what I'm looking for.  It's called the Ajax AutoComplete.

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question