Forum Moderators: coopster
With the code below, it shows 'Active', then 'Active' again followed by the other 3 items.
How can I get it to show just the current value, which can be any of the 4 options, then only show the current value and then only the other 3.
<select name='status'>
<option value=$status selected='selected'>$status</option>
<option value='Active'>Active</option>
<option value='Available'>Available</option>
<option value='Lost/Stolen'>Lost/Stolen</option>
<option value='Retired'>Retired</option>
</select>
Thanks!
$select_options = array(
'Active' => 'Active',
'Available' => 'Available',
'Lost/Stolen' => 'Lost/Stolen',
'Retired' => 'Retired'
);
echo '<select name="status">';
foreach($select_options as $value=>$label){
echo '<option value="'.$value.'"'.( ($value == $status)? ' selected="selected"' : '' ).'>'.$label.'</option>';
}
echo '</select>';
// uses same $select_options array from before
echo '<select name="status">';
if(isset($select_options[$status])){
echo '<option value="'.$status.'" selected="selected">'.$select_options[$status].'</option>';
}
foreach($select_options as $value=>$label){
if($status != value){
echo '<option value="'.$value.'">'.$label.'</option>';
}
}
echo '</select>';