I have a mysql entry as an integer 1 to 10. I want to display the result pre selected in a drop down. I am using -
<select name="Sleeps">
<?php
$sleeps = $row['Sleeps'];
$selectedId = array(1, 2, 3);
$selection = array(
1 => "1",
2 => "2",
3 => "3" );
foreach($selection as $value){
$text = $value;
$selected = '';
if ($selectedID == $sleeps) {
$selected = 'selected';
}
echo '<option value="'.$text.'" selected="'.$selected.'">'.$text.'</option>';
}
?>
</select>
This nearly works as I get -
<option value="1" selected="selected">1</option>
<option value="2" selected="selected">2</option>
<option value="3" selected="selected">3</option>
But all options have selected="selected" and i just want the value I have in my db selected which I believe should just be 'selected' text like -
2
Please help I am new to this