在sql中通过while循环无法获取计数值?

时间:2013-03-04 06:32:45

标签: php mysql count while-loop

我还需要让发送邮件计数的用户。

$userlist = mysql_query("select count(distinct m.subject) as msgcnt, u.name from message as m, message_users as mu, users as u where m.owner_id = u.id and m.id=mu.msg_id and mu.user_id='$u_id'group by name") or mysql_error();
        while($row=mysql_fetch_array($userlist))
        {               
            echo $row['name']."<br />";
        }

如何使用while循环获取计数值..

4 个答案:

答案 0 :(得分:3)

您已将所述计数存储在别名msgcnt中,只需将其回显即可。

while($row=mysql_fetch_assoc($userlist))
        {               
            echo $row['name']." : ".$row['msgcnt']."<br />";
        }

答案 1 :(得分:1)

echo $row['msgcnt'].'<br/>';

答案 2 :(得分:0)

使用mysql_fetch_assoc获取关联的数组!

$userlist = mysql_query("select count(distinct m.subject) as msgcnt, u.name from message as m, message_users as mu, users as u where m.owner_id = u.id and m.id=mu.msg_id and mu.user_id='$u_id'group by name") or mysql_error();
while($row=mysql_fetch_assoc($userlist)) {               
        echo $row['name']."<br />";           
        echo $row['msgcnt']."<br />";
    }

答案 3 :(得分:0)

在您将别名指定为msgcnt

时使用msgcnt
echo $row['msgcnt']."<br />";