PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I'm creating a menu where a user can add an access level to it via an select option. I have managed to get it to select and add it to database when a user creates a link. But I don't know how to get it to automatically select the access level option when they go to edit the link. Can this be done by an if-else statement, and if yes, can somebody please show me how?
So far I can get checkboxes to automatically be ticked by this code:
And for example, if a user creates a new link and selects the access level to be for example VIP. The next time that (or another) user goes to edit that link the name VIP will be automatically selected. Will your way work for this?
$name = 'jimmy'; //an example; //An example name;
$selected = array($name => 'selected="selected"'); //If name is selected then add this?;
$names = array('ben', 'jimmy', 'john'); //names in array that are allowed;
echo '<select>';
foreach($names as $key => $value)// Have no idea
echo '<option '.((isset($selected[$value])) ? $selected[$value] : null).'>'.$value.'</option>'; // The $selected[$value'] adds the 'selected="selected" from the $selected variable ONLY if the $name matches the one in the array. If not then it is set to null?
echo '</select>';
Well I think I get some of it, but maybe you can explain a little better
One problem though How can I add before the names? I've the following without any luck. I don't really require it, it just makes it look more neat