If your list of permissions is a fixed length set, you can simply create and array of those permissions

$perms = array('create','insert','update','delete');

The functions that have these permissions can be stored in a table and just retrieved thru a loop. To create your matrix structure of permissions and functions, you loop thru the permissions as you loop thru the fuctions data set

ex

while($rows=mysql_fetch_array($result))
{
 $func = $rows['function_name'];
 echo "<tr><td>$func</td>";

 foreach($perms as $key =>$value)
 {
echo "<td><input type='checkbox' name='perm_$func_$value' value='1'>$value</td>";
 }
 echo "</tr>";
}



the above code would create a table row with the function name, then a series of checkboxes with the value of the checkbox being the index element of the array and a name of perm_ and the function name and the name of the permission to be able to relate the permissions back to the function name

Does this help?

Bastien


From: "ron.php" <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
CC: php-db@lists.php.net
Subject: [PHP-DB] Processing web forms
Date: Sun, 16 Apr 2006 07:29:51 -0400


I am not sure how to apply the

array ('priv1', 'priv2', 'priv3' ...);

to what I am programming because the number of web functions will be
increasing --- it isn't a set number. I have never worked with arrays before.

Is there another way to define the array?  I am storing information about
these functions in a table and I could run a query to find out how many there are and what their values are and populate the array this way. What I really want to do is to take the results of the form --- which boxes are checked in and compare them with a user permissions table I have designed and then make
the table match the form which was just submitted with a series of DELETE,
UPDATE and INSERT commands.  There is a second field in this I haven't
mentioned yet --- a performance review date associated with those who have
been given access to each function.

Ron


Ron,

One option is to build a list of privs and iterate over that for the form
and processing

To do that, you would iterate over the list and use variables to name the
fields. When you process the form, you would iterate over the same list and
extract the values.

Form building:

$foo = array ('priv1', 'priv2', 'priv3' ...);
...
foreach ($foo as $priv) {
        ...
        <input type="checkbox" name="<?php print $priv; ?>"><?php print
$priv; ?>
        ...
}

Form processing:

foreach ($foo as $priv) {
        if (isset($_POST[$priv])) {
                do something here like update the database or build one SQL
statement
        }
}

Instead of using a list when you build foo, you could use a hash.

$foo = array('priv1' => 'Man readable priv 1', 'priv2' => 'Man readable priv
2', 'priv3' => 'Man readable priv 3' ...);
...
foreach (array_keys($foo) as $priv) {
        ...
        <input type="checkbox" name="<?php print $priv; ?>"><?php print
$foo[$priv]; ?>
        ...
}

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to