how to fetch data from database in php and display in select option code example

Example 1: get data from database in dropdown list php

<?php
$connect = new mysqli("127.0.0.1","root","");

			if ($connect -> connect_errno)
				{
			  		echo "Failed to connect to MySQL: " . $connect -> connect_error;
			  		exit();
				}

					$connect -> select_db("Your Database");
				if ($result = $connect -> query("Your query")) 
  				{
			  		
				}
				echo "<select>";
				while($row = mysqli_fetch_array($result)) 
				{
					echo "<option>" . $row['Your columns'] . "</option>"
				}
				echo "</select>"
?>

Example 2: php code for fetching data from database

CREATE DATABASE company;
CREATE TABLE employee(
employee_id int(10) NOT NULL AUTO_INCREMENT,
employee_name varchar(255) NOT NULL,
employee_email varchar(255) NOT NULL,
employee_contact varchar(255) NOT NULL,
employee_address varchar(255) NOT NULL,
PRIMARY KEY (employee_id)
)
Copy

Tags:

Php Example