HOT NEWS
Using Php to Populate a Drop Down List Box From a Mysql Database Table
(2 votes, average 5.00 out of 5)
User Rating: / 2
PoorBest 
Web Design
Written by Administrator   
Friday, 28 August 2009 20:17
Hits smaller text tool iconmedium text tool iconlarger text tool icon

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 the items 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, database-table.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.

database-table.sql

create table years
(  yearID integer auto_increment,
year varchar(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 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.

populate-list.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.

John Dixon

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.



Add this page to your favorite Social Bookmarking websites
Digg! Reddit! Mixx! Free and Open Source Software News Google! Live! Netscape! StumbleUpon! MySpace! Spurl! Wists! Simpy! Fark! Blogmarks! Squidoo! FeedMeLinks! Ask! DZone! ShoutWire! MyLinkVault! BlogRolling! TwitThis Joomla Free PHP
 
Please register or login to add your comments to this article.

Sponsers





SEO Tips

Search Engine Optimization And The Magic

Search Engine Optimization And The Magic Fairy Dust There is only one thing that all webmasters agree upon... They all want to be at the top ... READMORE

Keyword Discovery (Keyphrase Research) M

Keyword Discovery or Keyphrase Research is of high importance in the success of any website. Internet searchers use keywords and key phrases to find what ... READMORE

Basic SEO Services That Will Definitely

Basic SEO Services That Will Definitely Improve Traffic To Your Site Every website needs to consider search engine optimization or SEO services. This will serve as ... READMORE

How It Is Beneficial To Submit SEO Artic

How It Is Beneficial To Submit SEO Articles? There are so many website designed by different companies as these are different types of business and ideas. ... READMORE

More in: SEO - (Search Engine Optimization)

-
+
4

WebMaster Tips

How To Get Traffic Without Spending A Di

How To Get Traffic Without Spending A Dime Starting a brick and mortar business requires an enormous capital investment. Today, online businesses are able to compete ... READMORE

If You Build It, Will They Come?

When some business owners launch their websites, they wait for that success they’ve heard so much about, to start rolling. I’ve heard some business owners say ... READMORE

21 Free and Easy Techniques to Increase

Traffic is the lifeblood of your website. You could have the best website on the planet, but without traffic, no one will see it and ... READMORE

Landing Page Secrets Revealed

Landing Page Secrets Revealed Landing page techniques are changing. Often we hear them called "lead capture pages", "lead generation pages", "opt in pages", "name squeeze pages" ... READMORE

More in: Web Design Key Points

-
+
4

Made By NerrawSoft

Joomla Tarot Reader

tarot_rdr_tn

JoomSolo 2.10a

jsolo_gc_tn

Dream Dictionary

dream_dictionary_tn

JoomSolo 2.10b

jsolo_ff_tn