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 record that appears (this is very similar idea to the permission admin panel in phpBB). In other words, I have a table that lists all of the groups that a user could belong to, and in each row there are select menus for changing the permissions of that group. I am currently using functions for each different set of menus that looks like this:
function rfiPermissions($x){
$query = "SELECT rfi_permission FROM groups WHERE id = '$x'";
$result = mysql_query($query) or die();
$row = mysql_fetch_array($result);
$perm = $row[0];
$option = array();
$option[0] = "<option value='0'>None</option>";
$option[1] = "<option value='1'>Basic</option>";
$option[2] = "<option value='2'>Supplemental</option>";
$option[3] = "<option value='3'>Full</option>";
switch($perm){
case 0:
echo $option[0].$option[1].$option[2].$option[3];
break;
case 1:
echo $option[1].$option[0].$option[2].$option[3];
break;
case 2:
echo $option[2].$option[1].$option[0].$option[3];
break;
default:
echo $option[3].$option[1].$option[0].$option[2];
break;
}
}
I have been trying to figure out a more stream-lined way of doing this because I need to implement this many more times in my site, but I have been unable to do so. Is there a better way of doing this where I can simply pass an array of what the options need to be into a function, then echo the one value from the db, remove it from the array, then echo the rest of the options?