I am trying to retrieve a stored value from database and show it in a select option box. My problem is it's showing the first value as selected. my code is
$query = "SELECT * FROM bookwizard.book_inventory where bi_SKU='$SKU'";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
$bid=($row{'bi_bookcondition_id'});
}
<select class='form-control' id='condition' name='condition'>
<option value='' <?php if (!empty($bid) && $bid == '' ) echo 'selected = 'selected'; ?> </option>
<option value='1' <?php if (!empty($bid) && $bid == '1') echo 'selected = 'selected'; ?>Good</option>
<option value='2' <?php if (!empty($bid) && $bid == '2') echo 'selected = 'selected'; ?>Old</option>
<option value='3' <?php if (!empty($bid) && $bid == '3') echo 'selected = 'selected'; ?>Bad</option>
</select>
Thanks for helping.