php - Dropdown from DB with first option empty -
$query = mysql_query("select distinct(city) contacts"); echo '<select name="city">'; while ($row = mysql_fetch_array($query)) { echo '<option value="'.$row['city'].'">'.$row['city'].'</option>'; } echo '</select> <br />';
this pice of code show cities database. default, first city selected. first option "select city" no value.
how think in context?
just add option tag before while loop
$query = mysql_query("select distinct(city) contacts"); echo '<select name="city">'; echo '<option value="">select city</option>'; while ($row = mysql_fetch_array($query)) { echo '<option value="'.$row['city'].'">'.$row['city'].'</option>'; } echo '</select> <br />';
Comments
Post a Comment