php - Set index of dropdown list to value -


i have dropdown list

   <label for="stafftype">staff type<br /></label>       <select id="mylist" name="stafftype" onchange="show()">         <option>care staff</option>         <option>nursing staff</option>         <option>administrator</option>       </select> 

i want set index $user['stafftype'].

what best way? php code create user object

<?php while ($cursor->hasnext()): $user = $cursor->getnext(); ?> 

depdending on how set dropdown values, need give condition set if corresponding value matches, if yes, set selected. consider example:

// db values $values_from_db = array(     array('id' => 1, 'stafftype' => 'care staff'),     array('id' => 2, 'stafftype' => 'nursing staff'),     array('id' => 3, 'stafftype' => 'administrator'), );  // current value checked $user['stafftype'] = 'administrator';  // don't know how select box values rendered <label for="stafftype">staff type<br /></label> <select id="mylist" name="stafftype" onchange="show()"> <?php foreach($values_from_db $key => $value): ?>     <option <?php echo ($value['stafftype'] == $user['stafftype']) ? 'selected': ''; ?> ><?php echo $value['stafftype']; ?></option> <?php endforeach; ?> </select> 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -