Show dynamic Drop Down List in PHP by fetching MySQL database data

How to get create drop down list in php directly via set MySQL db records.

In this tutorial we are creating complete dynamic drop down list and inside that list all the list items directly coming from MySQL db table rows-columns. Means all you have to is enter the value directly to db and it will call and set them inside drop down list using PHP. So here is the complete step by step tutorial for Show dynamic Drop Down List in PHP by fetching MySQL database data.

android-project-download-code-button

How to Show dynamic Drop Down List in PHP by fetching MySQL database data.

Code for dynamic-drop-down-list.php file.

 <!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Show dynamic Drop Down List in PHP by fetching MySQL database data</title>
</head>

<body>


<?php

include 'dbconfig.php';

$subjectName = "SELECT * FROM demo_table_8 value";

$subject = mysql_query( $subjectName, $conn );

?>
<h2> Dynamic Drop Down List </h2>
 
 <form method="post" action=" ">
 
 <label >Subject</label>
 
 <select name="subject_names">
 
 <option>---Select subject---</option>
 
 <?php while($subjectData = mysql_fetch_array($subject)){ ?>
 
<option value="<?php echo $subjectData['value'];?>"> <?php echo $subjectData['value'];?>

</option>

<?php }?> 

 </select>
 
 </form>

</body>
</html>

Code for dbconfig file.

 <?php

//Define your host here.
$hostname = "localhost";

//Define your database username here.
$username = "root";

//Define your database password here.
$password = "";

//Define your database name here.
$dbname = "test";

 $conn = mysql_connect($hostname, $username, $password);
 
 if (!$conn)
 
 {
 
 die('Could not connect: ' . mysql_error());
 
 }
 
 mysql_select_db($dbname, $conn);



?>

Screenshot:

Show dynamic Drop Down List in PHP by fetching MySQL database data

Click here to download Show dynamic Drop Down List in PHP by fetching MySQL database data project file with source code + MySQL database included.