<?php
$query="select usertable.id, name, username, dateofbirth, user_id from usertable INNER JOIN passbook on passbook.user_id=usertable.id ";
$result= mysqli_query($sql, $query);
$rowcount=mysqli_num_rows($result);
printf("Result set has %d rows.\n",$rowcount);
while($row=mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>";
echo $row["id"];
echo "</td>";
echo "<td>";
echo $row["name"];
echo "</td>";
echo "<td>";
echo $row["dateofbirth"];
echo "</td>";
echo "<td>";
echo $row["user_id"];
echo "</td>";
echo "</tr>";
}
?>
我试图在表中显示某个特定用户的图书数量。我使用了mysqli\u num\u rows查询,但它返回视图中的总行数。我想以表格数据的形式显示每个用户的图书数量。请帮忙。
2条答案
按热度按时间esyap4oy1#
从passbook.user\u id=usertable.id上的usertable inner join passbook中选择count(*)作为count、usertable.id、name、username、dateofbirth、user\u id
bfhwhh0e2#
在sql语句中使用groupby进行聚合(这不是要解决的php问题,而是db解决方案):