php - Creating dropdown list with data from sql and when post is called, keeping the tab selected -


ok, heres problem:

i can create dropdown list, when try , set last used tab selected runs through while query , selects bottom option.

heres code:

<?php     $sql="select id, description sites";      $result=mysql_query($sql);       $options="";       while ($row=mysql_fetch_array($result)) {          $id=$row["id"];          $thing=$row["description"];         $thing2 = $_post['thing'];         $options.="<option value='if (isset($_post['thing'])){ echo $thing2;  'selected='selected''}else{ echo $id}'>".$thing;     } ?>  <form action="" method="post" />     <select name="thing" id="thing">         <option value=0>all         <?=$options ?>     </select>      <input type="submit" name="submit" value="update"/> </form> 

how set selected tab 1 on after submit button clicked?

$options.="<option value='if (isset($_post['thing'])){ echo $thing2;  'selected='selected''}else{ echo $id}'>".$thing; 

needs change

$is_selected = isset($_post["thing"]) && $_post["thing"] == $id; $options.="<option value='".$id."'".($is_selected?" selected='selected'":"").">".$thing."</option>"; 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -