php & amp; option selected by mysql option selected

advertisements

when i try to selected option from sql in dropdown list i get all options is selected :

$status1 = $row7["status"];

if($status1 == "draft") { $slc = "selected"; }
if($status1 == "ordered") { $slc = "selected"; }
if($status1 == "shipped") { $slc = "selected";  }

echo "
  <select class=\"form-control input-sm\" name = \"o_status\">
    <option value = \"draft\" $slc>draft</option>
    <option value = \"ordered\" $slc>ordered</option>
    <option value = \"shipped\" $slc>shipped</option>
  </select>
";

my problem with output selected all options like that :

  <select class="form-control input-sm" name = "status">
<option value = "draft" selected>draft</option>
<option value = "ordered" selected>shipped</option>
<option value = "shipped" selected>shipped</option>


Please check now.

Hope this helps you:

$status1 = $row7["status"];

if($status1 == "draft") { $draft = "selected"; }
if($status1 == "ordered") { $ordered = "selected"; }
if($status1 == "shipped") { $shipped = "selected";  }

  echo "
  <select class=\"form-control input-sm\" name = \"o_status\">
 <option value = \"draft\" $draft>draft</option>
 <option value = \"ordered\" $ordered>ordered</option>
 <option value = \"shipped\" $shipped>shipped</option>
 </select>
  ";