Posted By

dato on 12/14/11


Tagged

select php forms


Versions (?)

Setting a select's selected value


 / Published in: PHP
 

dynamically selects a value in a select according to what's already in the DB

  1. function selecciona($dis)
  2. {
  3. $arr = array('None', 'option 1', 'option 2', 'option 3', 'option 4');
  4. for($i = 0; $i < count($arr); $i++)
  5. {
  6. $selected = ($arr[$i] == $dis) ? 'selected="selected"' : '';
  7. echo "<option value=\"{$arr[$i]}\" {$selected}>{$arr[$i]}</option>\n";
  8. }
  9. }

Report this snippet  

You need to login to post a comment.