JDT |
FREE Downloads |
|
Populate a Multi-Level Drop Down List Box from a MySQL Database Table |
||||
|
Every now and again it is necessary to produce a three-level drop down list box, where the user has to initially make a selection from the first list box, followed by one from the second, and then one from the third. The code to produce a multi-level drop down list box is reasonably complex and a bit too lengthy to reproduce in this tutorial. For this reason, the code has been zipped up and is freelay available here: Multi-Level Drop Down List Box. Quick OverviewOne potential problem when populating drop down list boxes from a database is that they can sometimes be slow to load in the browser. I once developed a three-level drop down list box that had 20 items in the first list box, about 250 in the second, and 10,000 in the third. If I had tried to populate all three list boxes when the web page was initially loaded, everything would probably have ground to a halt. To get around this problem I set up the list boxes so that only the first was populated when the web page was initially loaded. Once a selection had been made from this box, the second box was populated using a subset of the 250 items - based on the selection made from the first box. And then, finally, once a selection had been made from the second box, the third box was populated, using a subset of the 10,000 items, which was based on the selection made in the second drop down list box. The user also had the opportunity to select an item from the first list box only, or from the first and second list boxes, or from all three. dropdown.sqlUse this file to create a database called dropdown, and three database tables. If you do not want to use 'dropdown' as the database, edit this file. db.incEdit this file so the MySQL server connection constants are correct for your setup. php.iniIn order for the drop down list to work, the following must be set in the php.ini file: register_long_arrays = On Running the scriptPoint your browser at index.php. Go back to MySQL Tutorials home page Go back to Tutorials home page
|
|