how to fetch data from database in dropdown list in php?

Today, We want to share with you how to fetch data from database in dropdownlist in php?.In this post we will show you want to fetch data from database based on dropdown list selection using php, hear for how to retrieve data from database whenever select in drop down list in javascript we will give you demo and example for implement.In this post, we will learn about Jquery Ajax Dropdown Onchange Example In Php MySQL Database with an example.

how to show data in dropdownlist from database in php?

Step 1: Connection with Database



$link = mysqli_connect("localhost","root","[email protected]","products_data");

    die("Connection failed: " . mysqli_connect_error());


Step 2: Fetch data from database

Fetch data from database and display in drop down list

<!DOCTYPE html>
  <title>PHP Retrieve Data from MySQL using Drop Down Menu -</title>

    <option disabled selected>-- Select Category --</option>
        include "config.php";  // Using database connection file here
        $products_cat = mysqli_query($link, "SELECT cat_name From categories");  // Use select query here 

        while($product_categoty = mysqli_fetch_array($products_cat))
            echo "<option value='". $product_categoty['cat_name'] ."'>" .$product_categoty['cat_name'] ."</option>";  // displaying data in option menu

<?php mysqli_close($db);  // close the Database connection ?>


I hope you get an idea about php drop down list selected value from database.
I would like to have feedback on my blog.
Your valuable feedback, question, or opinions about this article are always welcome.
If you enjoyed and liked this post, donโ€™t forget to share.