Please, help me with this, I don't know what is going wrong!
| From: | Dani Matielo | Date: | Mon, 26 May 2003 00:32:33 +0000 |
| Subject: | Please, help me with this, I don't know what is going wrong! | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-148936@lists.php.net to get a copy of this message | ||
I have the following tables in my database:
permissoes, that contains the id and name of all permissions possible, like
id//permission
1//create user
2//delete user
3//edit user
and so on. I have another table called grupos with the group names and ids:
id//group
1//superuser
2//editor
3//user
and so on. And then I have a 3 table that relate this 2 tables,
grupos_permissoes, containing id from the other groups.
id_grupos//id_permissoes
1//1
1//2
1//3
and so on. Very well. Then I am trying to validate every permission. If the
group has the permission, the function shoul return a value. If the group
doesnt have the permission, it returns another value. Here is what I did:
//this function lists all the permissions possible
function lista_permissoes() {
$result = mysql_query("select * from permissoes ORDER BY ordem");
while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
$permissoes[] = $row;
}
return $permissoes;
};
//this one is supposed to check if the group has the permission
function validar($grupo,$perm) {
//here it selects all the permissions from a group
$permissao = mysql_query("select id_permissoes from grupos_permissoes where
id_grupos = $grupo");
$row = mysql_fetch_array($permissao,MYSQL_ASSOC);
//then I am checking if the array contains the permission I am checking
$acesso = 0;
if (in_array($perm,$row)) {
//then changing the value if it contains
$acesso = 1;
}
return $acesso;
}
//And then finally printing it down
?>
<html>
<?
$permis = lista_permissoes();
for($i=0; $i<=sizeof($permis); $i++) {
$permiss = $permis[$i];
$aux = validar(3,$permiss['id']);
if ($aux == 1) echo "Yes";
else echo "No";
}
?>
And here is my problem: he does everything right for the first permission
but for the rest it returns no... I dont know what is going wrong! Can you
help me out?
Thank you very much,
Dani
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.481 / Virus Database: 277 - Release Date: 13/5/2003