Codeaur Codeaur - 1 month ago 9
PHP Question

Trying to make a dynamic dropdown in php from database

I got a little question I want to make a dropdown menu from the data I get from the database.
I will get the following data

$starttime = 12:00:00
$endtime = 14:00:00
$talktime = 00:30:00


now I want to make a dropdown menu from it that it loops.
here is my example how I thought it would work.

for ($endtime = $starttime + $talktime){}


But as the code works I want to check the database if the data already exist. I know how to do that part only the loop I don't know.

Already thank you for the help.

Answer

You can try this

<?php
$starttime = new DateTime("12:00:00");
$endtime = new DateTime("14:00:00");
?>
<select name="" id="input" class="form-control" required="required">
<?php
while($starttime <= $endtime)
{

    echo "<option value='".$starttime->format('H:i:s')."'>".$starttime->format('H:i:s')."</option>";

    $starttime = date_add($starttime, date_interval_create_from_date_string('30 min'));
}
echo " </select>";