我想计算所有用户记录并将其显示在表格中,我正在尝试此代码,它只显示一个用户的记录,我想显示所有用户的记录。
$u=$_POST['userid'];
$result1 = mysqli_query($con,"SELECT COUNT(user_id) as total FROM table-name where user_id=$u");
echo "<table border='1'>
</tr>
<tr>
<th>User ID</th>
<th>count</th>
</tr>";
while($row = mysqli_fetch_array($result1))
{
echo "<tr>";
echo "<td>" . $u . "</td>";
echo "<td>" . $row['total'] . "</td>";
echo "</tr>";
}
echo "</table>";
}
答案 0 :(得分:1)
尝试以下SQL查询:
SELECT `user_id`, COUNT(`user_id`) as `total` FROM `table-name` GROUP BY `user_id`;
请参阅GROUP BY条款的文档。
答案 1 :(得分:0)
使用以下:
$ result1 = mysqli_query($ con,&#34; SELECT COUNT(user_id)as total FROM table-name&#34;);
where子句用于过滤数据。 参考http://www.w3schools.com/sql/sql_where.asp