I want to view some foods which I added through html and php code into database like food a, food b, food c, food d.
I want to view these food category in my dropdown list in another page of html as a updating food category .
<?php
$db_host = 'localhost'; // Server Name
$db_user = 'root'; // Username
$db_pass = ''; // Password
$db_name = 'rfid'; // Database Name
$conn = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
if (!$conn) {
die ('Failed to connect to MySQL: ' . mysqli_connect_error());
}
?>
<div class="sign_up">
<div class="formtitle" align="center">View Food Items </div>
<div class="top_section">
<div class="section">
<br>
<div class="input-sign details2">
<form name="form1" action="" method="post">
View Foods:
<?php
if ($result = @$dbconn->query("SELECT * FROM `food`"))
{
//`food` represents the table name.
echo "<select>";
while ($row = $result->fetch_assoc())
{
echo "<option value=\"".$row["food"]."\">".$row["food"]."</option>";
/*"id" and "foodname" represents the table column name.*/
}
echo "</select>";
}
?>
<select>
<option><?php echo $row["food"];?></option>
</select>
</form>
</div>
</div>
</div>
<div class="clear"> </div>
</div>