html - How to keep PHP dropdown selection on refresh inside a form? -


i want keep current selection in dropdown when submit form. how do that?

my code:

echo '<select name="roomselection">'; while ($row = mysqli_fetch_array($selectroom1)) {     echo '<option value="'.$row['location'].'">'.$row['location'].'</option>'; } echo '</select>'; 

it's easy:

echo '<select name="roomselection">'; while ($row = mysqli_fetch_array($selectroom1)) {     echo '<option value="'.$row['location'].'"';     if($_post['roomselection']==$row['location']) echo ' selected ';      echo '>'.$row['location'].'</option>'; } echo '</select>'; 

you write selected if value equal post value. if form in method post, must adapt if it's in get.


Comments