显示每个用户的记录总数

$u=$_POST['userid'];

$sql=mysqli_query($con,"SELECT COUNT(username) AS total FROM TABLENAME where username=$u");

This query only retun the total records for username=$u

I want all users records to be displayed in total

I want something likes

User           Records
User1            1152
user2            2365
user3            2365 
------            -------
userN           XXX

I am using php and mysql.

Also please tell. What shall I echo, $sql or Total?

Thanks for your help

I tried this : and receiving error on line :

while($fetch = mysql_fetch_assoc($sql))

This is code that you guys gave me

'; print_r($array); mysqli_close($con); ?>

Thanks again

Try using GROUP BY

$sql = mysqli_query($con,"SELECT username, COUNT(username) AS total 
                          FROM TABLENAME GROUP BY username");

$array = array();
while($fetch = mysqli_fetch_assoc($sql))
{
    $array[$fetch['username']] = $fetch['total'];
}

echo '<pre>'; print_r($array);

$array will give you what you want.

This should do the trick, per user:

SELECT COUNT(username) AS total FROM TABLENAME GROUP BY username

SELECT COUNT(username) AS total FROM TABLENAME GROUP BY username

If you want to see which user it is as well, just add it to the SELECT:

SELECT username, COUNT(username) AS total FROM TABLENAME GROUP BY username

^As described in the question, that should do.

To display the results:

$u=$_POST['userid'];

$sql=mysqli_query($con,"SELECT COUNT(username) AS total FROM TABLENAME where username=$u");

while ($user = $sql->fetch_assoc()){
    echo($user["username"] . ": " . $user["total"]);
}