Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating a select menu in PHP with default selected from MySQL db
    primarykey
    data
    text
    <p>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:</p> <pre><code>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] = "&lt;option value='0'&gt;None&lt;/option&gt;"; $option[1] = "&lt;option value='1'&gt;Basic&lt;/option&gt;"; $option[2] = "&lt;option value='2'&gt;Supplemental&lt;/option&gt;"; $option[3] = "&lt;option value='3'&gt;Full&lt;/option&gt;"; 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; } } </code></pre> <p>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?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload