Remember Me
forgot your password?

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

Rate this Article: 4.2 / 5 stars - 22 vote(s)
Print Email Re-Publish

Add new Comment



Captcha
+1
1. gnana (13:28, 06.09.2008)
how to insert dropdown list in mysql db

  • Latest Web Design Articles
  • More from John Dixon

Vancouver Web Development Experts Can Create SEO-Friendly Website

By: David Scott | 18/12/2009
There are several issues that you have to address if you are going to start a web development project. Are you building a website just for the sake of getting a space in the cyber market? Are you starting the project to boost the integrity of your company? Or are you building a website to attract more customers? These are just some of the questions that you can present to a Vancouver web development service.

The Importance of Vancouver Graphic Design for Strengthening Brand Names

By: David Scott | 18/12/2009
Some business owners perceive graphic design as an unnecessary expense. You must never commit this mistake because in reality, graphic design is an investment that could bring lucrative profits for your company. Through effective utilization of graphic and web design, you can build a brand that people can identify. This means that your company’s brand will be etched in the subconscious of consumers which should give you a definite edge over your competitors.

5 Quick tips for getting rid of your website visitors

By: Matt Kline | 18/12/2009
You have probably read many articles and blog posts about how to build a website for converting online sales. I know that I have written plenty of them that deal with this issue. I thought this time I would go in the other direction and talk about what not to do on your website. After reading this, you will have no doubt about what to do in order to get rid of as many potential customers as you can. Not just get rid of them, but have them shaking their heads in disgust for minutes after they lea

Web templates are nothing but necessary point in website development & web market

By: Krishna Kant | 18/12/2009
Templates are the first phase in website designing process, after when we satisfied with template than we work on like put the code part and enhance our website. About web templates are nothing but redesign blueprint around which you can easily plan the web content.

A Guide for Choosing the Best Database Development Team

By: David Scott | 18/12/2009
Database development is a vast and complex field because new technologies, software and solutions are constantly emerging. In the field of web design, the integration of database requires meticulous planning and engineering. That is why you have to carefully choose the best Vancouver web development team that can display superior expertise on building database-driven websites.

The Unique Advantages of Flash Design for Your Business Website

By: David Scott | 18/12/2009
Flash design for websites has been getting a lot of favorable attention today. Many site owners prefer to use Flash technologies to make their websites more attractive and interactive. You have to take note that Flash based web applications are capable of displaying animations, interactive graphics, and highly engaging page navigations and buttons.

How to Find the Best Vancouver Internet Marketing Service

By: David Scott | 18/12/2009
It is quite obvious that major marketing campaigns are now conducted primarily on the Internet. Because of this, more companies are redrawing their marketing strategies. In the past, developing a website was not closely linked to Internet marketing. Today, website developments can only become successful if they are highly integrated with current Internet marketing practices and strategies.

Essential Web Authoring Software Features

By: Ross Carter | 18/12/2009
If you intend to create a web page for your personal use - or a complete website for your business needs, the first question you must ask is - what kind of features do you look for in a web page editor?

Using Php to Validate Form Fields

By: John Dixon | 24/07/2008 | Web Design
This article explains how to use PHP to validate data entered in form fields on a web page.

Finding Hidden Characters in a File

By: John Dixon | 27/06/2008 | Programming
It is sometimes necessary to find hidden characters within one or more files.

Web Site Promotion Tips

By: John Dixon | 20/06/2008 | SEO
When trying to get to the top of the search engine rankings there are certain things you should do, and other things you should not, in order to increase your chances of getting a top ten placement.

Exploiting Google Adsense

By: John Dixon | 08/04/2008 | Internet Marketing
Google Adsense provides a great way to generate revenue from a web site.

Using Perl and Regular Expressions to Process Html Files - Part 2

By: John Dixon | 17/03/2008 | Programming
In Part 1 we looked at what Perl and regular expressions are, and discussed how to use them to process ASCII files such as HTML files. In this part we'll develop a Perl script to process an HTML file.

Using Perl and Regular Expressions to Process Html Files - Part 1

By: John Dixon | 17/03/2008 | Programming
Like many web content authors, over the past few years I've had many occasions when I've needed to clean up a bunch of HTML files that have been generated by a word processor or publishing package. Initially, I used to clean up the files manually, opening each one in turn, and making the same set of updates to each one. This works fine when you only have a few files to fix, but when you have hundreds or even thousands to do, you can very quickly be looking at weeks or even months of work.

Size Really Does Matter

By: John Dixon | 14/03/2008 | SEO
I believe that by following three basic rules, it is relatively easy to achieve a high ranking with the major search engines: 1. Add lots of relevant content; 2. Build up plenty of good quality inbound links; 3. Be patient.

Submit Your Articles Free: Signup
Article Categories




Use of this web site constitutes acceptance of the Terms Of Use and Privacy Policy | User published content is licensed under a Creative Commons License.
Copyright © 2005-2008 Free Articles by ArticlesBase.com, All rights reserved. (0.09, 1, w3)