I am using the code below to create an authentication system. Ie each group of users has a number (1,2,4,8,16,32 etc...) each page then has a number value dependent on who can access that page ie index = 3 (2+1) and accounts = 28 (16+8+4).
I store these values in a DB and they are seleted by a multiple List menu, my problem is trying to edit using the list menu. I want the page to open up, select the record for that page, then show a list box with all the user groups, and the ones that can access the page are selected. Here is my code, but it only selects the 1st 2 always, regardless of the value.
$sql = "SELECT * from userlevels
";
#execute the query
$users = mysql_query($sql)
or die("Error!");
<select name="levels[]" size="<? echo "$numusers"; ?>" multiple>
<?
#now we'll loop thorugh and isert labels and values
while ($row = mysql_fetch_array($users)) {
$ulabel = $row['groupname'];
$ulevel = $row['grouplevel'];
echo " <option value=\"$ulevel\" ";
for($i=0;pow(2,$i) <= $levreq;$i++) {
if($levreq & pow(2,$i)) {
if($i == $ulevel){
echo "selected";
}
}
}
echo ">$ulabel</option>
";
}
$levreq is the Level Required and
$ulevel is the field in the user groups DB that contains the level value
Any help would be appreciated
Marcus