Reader Level:

Dropdown List in PHP

By Vineet Kumar Saini on Mar 03, 2012
In this article you will see how to create a static and dynamic drop down list in PHP.


A Dropdown list is a combination of items in a list. In the dropdown list menu only the title is visible but not the contents. The contents are shown only when the user activates it by a small arrow. The user may select an item from the menu by dragging the mouse from the menu title or by clicking the title and then clicking the item. The dropdown list box is read-only.

We can say a drop down list is a box containing a list of multiple items. A drop-down list is a list in which the selected item is always visible, and the others are visible on demand by clicking a drop-down button.

The main advantages of a drop down list is to save space because the number of views is not limited by space.

There are two types of dropdown lists, which are as follows:

  • Static dropdown list
  • Dynamic dropdown list

1. Static Dropdown list

Static dropdown list is used in the HTML form. Static means there are no database connectivity with the dropdown list.

An example of a static dropdown list is as follows:


title>Static Dropdown List</title>
body bgcolor="pink">
Employee List :
  <option value="Select">Select</option>}
  <option value="Vineet">Vineet Saini</option>
  <option value="Sumit">Sumit Sharma</option>
  <option value="Dorilal">Dorilal Agarwal</option>
  <option value="Omveer">Omveer Singh</option>
  <option value="Rohtash">Rohtash Kumar</option>
  <option value="Maneesh">Maneesh Tewatia</option>
  <option value="Priyanka">Priyanka Sachan</option>
  <option value="Neha">Neha Saini</option>



2. Dynamic Dropdown list

Dynamic dropdown list means, choose items from a list at run time. Dynamic dropdown list is used in the PHP form. Dynamic means there is database connectivity available for the dropdown list.

Step by step solution to create dynamic dropdown list

Step 1. First of all we create a database in MySql using the following query.

           CREATE DATABASE `company`;

Step 2. After that then we create a table in the database. For create table in the database you can use the following query.

           CREATE TABLE `company`.`employee` (`emp_id` INT(10) NOT NULL AUTO_INCREMENT, `emp_name` VARCHAR(30) NOT NULL,
           PRIMARY KEY(`emp_id`)) ENGINE = InnoDB;

Step 3. Now we insert the values in the table using the following queries.

           insert into employee (emp_id,emp_name) values(0,'Vineet Saini');
           insert into employee (emp_id,emp_name) values(0,'Sumit Sharma');

           insert into employee (emp_id,emp_name) values(0,'Dorilal Agarwal');

           insert into employee (emp_id,emp_name) values(0,'Omveer Singh');

           insert into employee (emp_id,emp_name) values(0,'Maneesh Tewatia');

           insert into employee (emp_id,emp_name) values(0,'Rohtash Kumar');

           insert into employee (emp_id,emp_name) values(0,'Priyanka Sachan');

           insert into employee (emp_id,emp_name) values(0,'Neha Saini');

Step 4. When we execute the above query then you will get the following table.


Step 5. Now we will use the above table in the dropdown list using the following code.


    <title>Dynamic Drop Down List</title>
    <BODY bgcolor ="pink">
        <form id="form1" name="form1" method="post" action="<?php echo $PHP_SELF; ?>">
            Employee List :
<select Emp Name='NEW'>
            <option value="">--- Select ---</option>
                mysql_connect ("localhost","root","");
                mysql_select_db (
if (isset ($select)&&$select!=""){
                $select=$_POST [
                $list=mysql_query("select * from employee order by emp_id asc");
                    <option value="<? echo $row_list['emp_id']; ?>"<? if($row_list['emp_id']==$select){ echo "selected"; } ?>>
<?echo $row_list['emp_name'];?>
            <input type="submit" name="Submit" value="Select" />




So in this article you saw how to create a static dropdown list and dynamic dropdown list. Using this article one can easily understand how to create static and dynamic dropdown lists in PHP.

Some Helpful Resources

Vineet Kumar Saini
Vineet Kumar Saini

Vineet Kumar Saini is MCA qualified with Honors from SunderDeep Engineering College Ghaziabad. Currently he is working as a "WEB Developer" at AzylApps Technology Pvt. Ltd.



Spire.Doc - Free .NET Word API
Use Spire.Doc to create, read, write, print, and convert word documents to OpenXML, RTF, TXT, XPS, EPUB, EMF, HTML, Image and PDF.

Trending up