0

I need to get the users who sends the message count as well.

$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 />";
        }

How to get the count values by using while loop..

1
  • $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(); query issue might be give space mu.user_id='$_id' group by Commented Mar 4, 2013 at 6:34

4 Answers 4

3

You already are storing the said count in an alias msgcnt, simply echo it.

while($row=mysql_fetch_assoc($userlist))
        {               
            echo $row['name']." : ".$row['msgcnt']."<br />";
        }
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

0

use mysql_fetch_assoc to get a associated array!

$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 />";
    }

Comments

0

use msgcnt when you specified alias as msgcnt

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.