Search
Links
Advertising
Links

Using Php To Populate A Drop Down List Box From

Using Php To Populate A Drop Down List Box From A Mysql Database Table

Quite often when you are developing web sites or applications it is necessary to create a drop down list box that contains entries from a database table. You can of course hard code theitems in the drop down list box but this isn’t really very elegant and can create problems if the entries in the database table change at a later date. It is much better to extract the entries from the database table directly and then populate the drop down list box using those entries.

Creating the database table

The following script databasetable.sql could typically be used to create a database table called ‘years’ that contains for example a list of years. These will be the entries that appear in the drop down list box.

databasetable.sql

create table years
yearID integer auto_increment
year varchar30
primary key yearID
;

insert into years yearID year values ’1′ ’20072008′;
insert into years yearID year values ’2′ ’20082009′;
insert into years yearID year values ’3′ ’20092010′;
insert into years yearID year values ’4′ ’20102011′;
insert into years yearID year values ’5′ ’20112012′;
insert into years yearID year values ’6′ ’20122013′;

The following PHP script populatelist.php which would form part of a form will extract all the entries from the ‘years’ database table and use them to populate the drop down list box.

populatelist.php

Drop Down List Box

If the entries in the database table change at some stage in the future those changes will be automatically reflected in the drop down list box in the form.

About the writer:  John Dixon is a web developer working through his own company John Dixon Technology. In addition to providing web development services John’s company also provides a free accounting tool called Earnings Tracker as well as other free software downloads various tutorials articles a business and finance blog and several news feeds.

Related posts:

  1. Building Your Business With An Opt-in List
  2. What Is The Best Opt-In List Building Tips
  3. Object-SQL Mapping On Software Development
  4. Do You Think Opt-in List Is Necessary
  5. How To Build A Massive List Of Niche Buyers

Comments are closed.

Categories
Calendar
February 2012
M T W T F S S
« Jan    
 12345
6789101112
13141516171819
20212223242526
272829  
Review www.my-hostingtips.com on alexa.com