Using Php to Populate a Drop Down List Box From a Mysql Database Table

5 Nov

Often develop if you create Web pages or applications, it is necessary to establish a combo box that contains entries of a table of database. You could always hard code the items in the dropdown list, but it's not very elegant, and can lead to problems if the entries in the change database table at a later date. It's much better to extract directly from entries in the database table data and then fill the dropdown list box with entries.
Creating the database table data
The following script, table database. SQL, which are commonly used to create a table of database (called "year") which includes, for example, a list of years. These are the entries that appear in the dropdown menu.
database table. SQL
years to create table (yearID auto_increment integer, varchar, year (30), PRIMARY KEY (yearID));
insert into years (yearID, year) values ('1 ', '2007-2008') INSERT INTO years (yearID, year) values ('2 ', '2008-2009') INSERT INTO years (yearID, year) values ( '3 ', '2009-2010') INSERT INTO years (yearID, year) values ('4 ', '2010-2011') INSERT INTO years (yearID, year) values ('5 ', '2011 -2012') insert into years (yearID, year) values ('6 ', "2012-2013");
The following PHP script populate list. (Php) which would constitute a form to extract all entries in the table 'years of database and use it to fill the combo box.
Complete list. php

If the entries on the table of database at some point in the future, changes are automatically reflected in the combo box on the form.

John Dixon is a web developer working for his own technology company Dixon, John. In addition to providing web development services, John's company also offers a free tool called accounting profit Tracker and other free software downloads, tutorials various RSS feeds, articles, business and finance and Blog news.

Or for further references, check out the following resources:

2 Responses to “Using Php to Populate a Drop Down List Box From a Mysql Database Table”

  1. Susan Kishner 05. Nov, 2009 at 1:22 am #

    Great post. I will read your posts frequently. Added you to the RSS reader.

  2. Susan Kishner 05. Nov, 2009 at 1:27 am #

    Thanks for posting the article, was certainly a great read!

Leave a Reply