Creating A Select Menu In Php With Default Selected From Mysql Db
I am creating an admin menu for a site and I have several drop down lists that need to be created for each different field with the default selected option being different for each
Solution 1:
It is easier to set the selected attribute with php than to change the order. Plus, as a user I like consistency and if I looked at a drop down and the order changed each time I looked at it I would be frustrated.
$option[0] = "<option value='0' ".($perm==0 ? " selected " : "") .">None</option>";
$option[1] = "<option value='1' ".($perm==1 ? " selected " : "") .">Basic</option>";
$option[2] = "<option value='2' ".($perm==2 ? " selected " : "") .">Supplemental</option>";
$option[3] = "<option value='3' ".($perm==3 ? " selected " : "") .">Full</option>";
This is done in if short hand and can be expanded for readability
Post a Comment for "Creating A Select Menu In Php With Default Selected From Mysql Db"