需要知道获取每个管理员角色的用户总数并打印出来的语法是什么。
Roles
id | name
--- ----
1 | admin
2 | moderator
3 | user
表 2
users
id | name | role
-- ---- ----
1 | a | 1
2 | b | 2
3 | c | 2
4 | d | 2
5 | e | 3
6 | f | 3
7 | g | 3
8 | h | 1
9 | i | 1
代码
<?php
$sql = "select r.name, r.id from role r, users u where r.id=u.role";
$result = mysql_query($sql);
$count = 0;
while($row = mysql_fetch_array($result))
{
if($count!=$row['1'])
{
echo $row['0']."- NEED TOTAL NUMBER OF USERS ON EACH ROLES TO BE PRINTED HERE.";
$count=$row['1'];
}
?>