This code finally worked to display a previous selection $MedIDinDB in a lookup table based select box as desired, but it will not allow a new selection to change the control's selected value for posting an update as needed. How do I do both?

```
<select name="MedSelect" value="<?php 

$sql = "SELECT MedID, MedName FROM Meds ORDER BY Rank ASC";
$query = $pdo->prepare($sql);
$query->execute();
if($query) {
    $row = $query->fetchAll(PDO::FETCH_ASSOC);
    foreach($row as $value){ ?>
        <option value="<?php echo $value['MedID']; ?>"<?php if ($value['MedID'] == $MedIDinDB) echo ' selected="selected"'; ?>><?php echo $value['MedName']; ?> 
        </option>
<?php }} ?>

</select>

```