I am trying to provide drop down list in input field using values from MySQL. I tried a lots of examples from web but no one works. Here is my code.
<div class="form-group">
<input autocomplete="off" autofocus class="form-control" name="date" id="datepicker" placeholder="Date" type="text"/>
<input autocomplete="off" autofocus class="form-control" name="diagnosis" placeholder="Diagnosis" type="text"/>
<input autocomplete="off" autofocus class="form-control" name="therapy" placeholder="Therapy" type="text"/>
<input autocomplete="off" autofocus class="form-control" name="comment" placeholder="Comment" type="text"/>
<input list="doctors" autofocus class="form-control" name="doctor" placeholder="Doctor" type="text"/>
<datalist id="doctors">
<?php $result= CS50::query("SELECT name FROM doctors");
foreach($result as $result): ?>
<option value="$result["name"]">
<?php endforeach ?>
</datalist>
</div>
or
$names= CS50::query("SELECT name FROM doctors");
while ($row=mysql_fetch_array($names)) {
$name=$row["name"];
echo "<option>
$name
</option>";
}
Thanks for help!