This below is the code I am using to display a dropdown dynamically.But I am unable to retain the value of the dropdown after posting it?I am able to insert the values and able to retain the values for textboxes..but unable to retain for dropdown
Available Doctors
<?php
$selectedDoctor = $_POST["doctortype"];
$sql = "select firstname from users where userid in (select userid from doctortype where doctortype = \"$selectedDoctor\");";
include_once("inc_databaseClass.php");
$dClass=new databaseClass;
$results=$dClass->connect();
$result = mysqli_query($results,$sql);
echo "<select name = 'selectDoctors' id = 'idaname'>";
echo "<option value = ''>";
while ($row = mysqli_fetch_array($result)) {
$selected = (isset($_POST['selectDoctors']) && $_POST['selectDoctors'] == $row['firstname']) ? 'selected = "selected"' :'';
?>
<option <?php echo $selected; ?> value = "<?php echo $row['firstname']; ?>"> <?php echo $row['firstname']; ?> </option>
<?php } ?>
</select>
</p>