PHP Combo Box (like in MS Access)

Posted on 2012-09-11
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
    LVL 3

    Assisted Solution

    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 82

    Accepted Solution

    You can use 'autosuggest' which brings up possibilities as you type.  It's really not that much load on a shared server since no one can type fast enough to cause a problem.

    Author Comment

    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?
    LVL 82

    Expert Comment

    by:Dave Baldwin
    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.
    LVL 107

    Assisted Solution

    by:Ray Paseur
    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

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
    Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to count occurrences of each item in an array.

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now