I have one form that is used for adding and editing. My goal here is to on the add form have it pre-select the count(items)+1 value. On the edit form I need it to pre-select the value from the database when it it matches the increment of the for loop. Right now the $selected value isn’t working and I”m not sure how to implement the part for the add form. Any ideas?
<?php for($x = 1; $x <= count($items)+1; $x++)
{
if (isset($item_data))
{
$selected = $item_data->item_sort_order === $x ? ' selected="selected"' : '';
}
echo '<option value="'.$x.'"';
if (isset($selected)) { echo $selected; }
echo '>'.$x.'</option>';
}
?>
I think you need to reset the
$selectedvariable each time. Once its set, then it remains so. Try this:EDIT: