Creating Dynamic Drop Down List in PHP


In this article I will explain creation of a Dynamic Drop Down List in PHP using a MySQL database. Such that, when you want to insert, delete or update data in our drop down list box, you directly insert, update or delete from the database. This phenomenon is called a dynamic drop down list. This drop down list dynamically fetches data from the database. This phenomenon I will describe here just with an example. 
Dynamic Dropdown List.jpg


In the following code, some car names are in my database and these car names are shown in our dropdown list dynamically.




<title>Dynamic Drop Down List</title>


<Body background="as.jpg">

<form id="form1" name="form1" method="post" action="<?php $_SERVER['PHP_SELF']?>">

Car Name:

<select name='NEW'>

<option value="">--- Select ---</option>










$list=mysql_query("select * from car order by c_name asc");



<option value="<?php echo $row_list['c_id']; ?>">

 <?php if($row_list['c_id']==$select){ echo "selected"; } ?>

 <?php echo $row_list['c_name']; ?>









dropdown list with database.jpg

dropdown list with database1.jpg

I will just insert some car names into our table and then refresh our localhost browser so the dropdown list box is automatically updated dynamically. Such that:

dropdown list with database2.jpg

dropdown list with database3.jpg

Up Next
    Ebook Download
    View all
    View all