我想创建一个可以通过此级别表访问数据的管理员组, 低级别无法看到更高级别的数据。
0 => 3
高=>的低
用户表:
---------------------
uid gid uname
---------------------
110 4 Jacky =>means {gname: art_admin ,level: 2}
111 1 Niky =>means {gname: site_admin ,level: 0}
112 4 Cupe =>means {gname: art_admin ,level: 2}
113 2 Nancy =>means {gname: gen_admin ,level: 1}
113 5 Joe =>means {gname: admin ,level: 3}
小组表:
---------------------
gid gname level
---------------------
1 site_admin 0
2 gen_admin 1
3 sys_admin 1
4 art_admin 2
5 admin 3
这意味着Jacky属于'art_admin',他的等级为'2'。 所以当他查看所有用户表时,它只显示2以下的级别。
然后,我该如何查询呢?感谢。
伪码
$uid = 110 ;// Assume I'm Jacky
$result = mysql_query("
SELECT
user.uname from user
WHERE
[ group.level >= Jacky's level ]
";);
while($row = mysql_fetch_array($result)){
echo $row['uname']." , ";
}
它应该返回
Jacky , Cupe , Joe
答案 0 :(得分:3)
这是您要查找的查询吗?
select u.uname
from user u join
groups g
on u.gid = g.gid
where g.level >= (select g2.level
from user u2 join
groups g2
on u2.gid = g2.gid
where u2.uname = 'Jacky'
);