Dependent dropdown example in PHP MySQL

Rate this post

Today, We want to share with you Dependent dropdown example in PHP MySQL.In this post we will show you dependent drop down list php, hear for PHP – How to make dependent dropdown list using jquery Ajax we will give you demo and example for implement.In this post, we will learn about jQuery Dependent DropDown List in PHP MySQL with an example.

Dependent dropdown example in PHP MySQL

There are the Following The simple About Dependent dropdown example in PHP MySQL Full Information With Example and source code.

As I will cover this Post with live Working example to develop dependent drop down list in php, so the some major files and Directory structures for this example is following below.

Free Live Chat for Any Issue
  • index.php
  • db.php
  • get_products.php
Read Also:  MySQL get column names – BEST 5 WAYS TO “mysql get column names”

Database connection in PHP


//dependent dropdown in php Database Connection
$conn = new mysqli('localhost', 'root', '', 'dependent_dropdown');
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);

HTML Interface View files


This is where I will make a simple HTML form and PHP server side source code for our web application. To make the forms simply all souce code copy and write it into your any text editor Like Notepad++, then save file it as index.php.

<h2>Dependent Dropdown in php MySQL</h2>
$member_result = $conn->query('select * from members');
?><select name="member" id="members-list">
<option value="">Select Member</option>
	if ($member_result->num_rows > 0) {
		// output data of each row
		while($row = $member_result->fetch_assoc()) {
			<option value="<?php echo $row["id"]; ?>"><?php echo $row["member_name"]; ?></option>
<select name="product" id="products-list">
<option value=''>Select Product</option>

<script src=""></script>
$('#members-list').on('change', function(){
	var member_id = this.value;
		type: "POST",
		url: "get_products.php",
		success: function(result){

Retrive All ProductsList


$member_id = mysql_real_escape_string($_POST['member_id']);
		$products_result = $conn->query('select * from products where member_id='.$member_id.'');
		$options = "<option value=''>Select Product</option>";
		while($row = $products_result->fetch_assoc()) {
		$options .= "<option value='".$row['id']."'>".$row['product']."</option>";
echo $options;

Angular 6 CRUD Operations Application Tutorials

Read :

Read Also:  How to play audio using javascript?


You can also read about AngularJS, ASP.NET, VueJs, PHP.


I hope you get an idea about Dependent dropdown example in PHP MySQL.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.