<select> dropdown default value <select> dropdown default value php php

<select> dropdown default value


Just put selected="selected" on the option depending on your $row['status'],

<option selected="selected" value="available">Available</option>


write Available and Unavailable into an array

$theArray = array("Available","Not Available");

loop the array:

<tr><td><font face=consolas><b>Status:*</b></font></td><td><select name=st><?phpforeach ($theArray as $key => $value) {    if ($value == $stat) {        echo('<option selected="selected" value='.$value.'>'.$value.'</option>');    } else {        echo('<option value='.$value.'>'.$value.'</option>');    }}?></select></td></tr>

and in each loop we check if the value in the array, is the same as it is in the variable, if so, we put the selected there

understand the logic?


<select name=status><option value="available" <?php if($row['status']=="available") echo "selected=\"selected\""; ?>>Available</option><option value="unavailable" <?php if($row['status']=="unavailable") echo "selected=\"selected\""; ?>>Unvailable</option></select>

Basically echo selected="selected" for the option depending on value of the concerned field.