JDT

 

FREE Downloads
Articles
Tutorials

 

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 Overview

One 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.sql

Use 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.inc

Edit this file so the MySQL server connection constants are correct for your setup.

php.ini

In order for the drop down list to work, the following must be set in the php.ini file:

register_long_arrays = On

Running the script

Point your browser at index.php.







Go back to MySQL Tutorials home page

Go back to Tutorials home page



Earnings Tracker is John Dixon Technology's FREE accounting / bookkeeping software tool.

Aimed at contractors and freelancers, Earnings Tracker enables you to perform bookkeeping and accounting tasks, helping you to keep track of your company's revenue and spending.

The software is written in PHP and MySQL and is available to use for FREE online, or as a FREE download.

Earnings Tracker can also be used simply as a dividend, corporation tax, or VAT calculator.

Need free accounting software
 


JDT

Copyright Notice for John Dixon Technology Ltd

Privacy Statement

Terms & Conditions