How do you select a dropdown value inside a foreach loop. The code below generate time with 30 minutes gap. I cannot able to select the value from mysql database.
$sql = "SELECT * FROM batches WHERE batch_id = '$id'";
$result = mysqli_query($con, $sql);
while ($row = mysqli_fetch_array($result)) {
// Name
echo "<label>Batch name</label> ";
echo "<input type=text name=name value='".$row['name']."' required> <br />";
// Start time
echo "<label>Start time</label> ";
echo "<select name=starttime value=''> Start time </option>";
$range = range( strtotime("05:00"), strtotime("21:00"), 30 * 60);
foreach($range as $time){
$foo = date("H:i", $time) . "</br>";
$selected = ($foo == $row['start_time']) ? 'selected="selected"' : '';
echo "<option value='$foo'" . $selected . ">" . $foo . "</option>";
} // foreach
echo "</select>";
} // while
Please help!!