$u=$_POST['userid'];
$sql=mysqli_query($con,"SELECT COUNT(username) AS total FROM TABLENAME where username=$u");
此查询仅返回username=$u
我希望所有用户记录全部显示
我想要喜欢的东西
User Records
User1 1152
user2 2365
user3 2365
------ -------
userN XXX
我正在使用php和mysql。
另请告诉我。我应该回应什么,$sql
或Total
?
感谢您的帮助
我试过这个:并在线接收错误:
while($fetch = mysql_fetch_assoc($sql))
这是你们给我的代码
“;的print_r($阵列); mysqli_close($ CON); ?>再次感谢
答案 0 :(得分:3)
尝试使用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
会给你你想要的东西。
答案 1 :(得分:0)
这应该是每个用户的诀窍:
SELECT COUNT(username) AS total FROM TABLENAME GROUP BY username
答案 2 :(得分:0)
SELECT COUNT(username) AS total FROM TABLENAME GROUP BY username
如果你想看看它是哪个用户,只需将它添加到SELECT:
SELECT username, COUNT(username) AS total FROM TABLENAME GROUP BY username
^如问题所述,应该这样做。
显示结果:
$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"]);
}