I couldn't find a solution on here, thought I wasn't sure what to search for. I have a select box that is populated from my database using PDO. However I was unsure on how to set the selected value to a team that has already been set from the DB.
Update The code only shows the team that matches the variable, however I need to show all teams in the drop down.
<option <?php if($row4['team_id'] == $team_id) { ?>
selected="selected" > <?php }
echo $row4['team_name'];?>
</option>
<?php } ?>
OLD code
$stmt4 = $conn ->prepare('SELECT team_id, team_name FROM team_tbl ORDER BY team_name');
$stmt4->execute();
while($row4 = $stmt4->fetch(PDO::FETCH_ASSOC)) {
echo '<option <? if ($row4['team_id'] == $team_id){?> selected="selected"<? } ?>>'.$row4['team_name'].'</option>';
}
?>