<?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>";
}
?>
I am trying to display the number of books taken by a particualar user in the table. I have used the mysqli_num_rows query but it returns the total number of rows in the view. I want to display the number of books taken by each user as a table data. Please help.
您在SQL语句中使用GROUP BY进行了聚合(这不是要解决的PHP问题,而是数据库解决方案):
select count(*) as bookstaken, usertable.id, name, username, dateofbirth, user_id from usertable INNER JOIN passbook on passbook.user_id=usertable.id GROUP BY usertable.id, name, username, dateofbirth, user_id`
从passbook.user_id = usertable.id上的usertable INNER JOIN存折中选择count(*)作为count,usertable.id,名称,用户名,生日,user_id
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.