How to populate HTML select options from the values fetched from database using the PHP code is explained with example. Create Select drop down menu with values taken from database. I have used html, ajax, php & sql codes.

For create database “drinks” with table “list” run the following code in database SQL.

CREATE DATABASE drinks;

CREATE TABLE list (
id INT(2) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
D_Type VARCHAR(10) NOT NULL,
D_Name VARCHAR(10) NOT NULL
);

INSERT INTO list (id, D_Type, D_Name) VALUES (”, ‘Cold’, ‘Apple Juce’);
INSERT INTO list (id, D_Type, D_Name) VALUES (”, ‘Hot’, ‘Coffee’);
INSERT INTO list (id, D_Type, D_Name) VALUES (”, ‘Cold’, ‘Kiwi Juce’);
INSERT INTO list (id, D_Type, D_Name) VALUES (”, ‘Hot’, ‘Tea’);