mysql查询2个表并计数
您好,我有来自本地书店的以下查询/表,
$queryadmin ="SELECT last_name, first_name, user_id FROM users";
$recordz = @mysqli_query ($dbc, $queryadmin);
while ($row = mysqli_fetch_array($recordz, MYSQLI_ASSOC)) {
echo '<tr>
<td align="left">' . $row['first_name'] . '</td>
<td align="left">' . $row['last_name'] . '</td>
<td align="left">' . $row['user_id'] . '</td>
</tr>'
;}
现在我想要另一个表中的附加列,其中显示每个用户借出的书籍数量。 因此,查询如果单独嵌套会像这样将此
$query2 = mysql_query("SELECT FROM mirror3 WHERE userid='".$row['user_id']."'", $link);
$anzahl = mysql_num_rows($query2);
查询嵌套在上面的 while 查询中(就在启动之后),这是行不通的。怎么做呢?
提供的参数不是有效的 MySQL 结果资源
谢谢
Hi i have the following query/table from a local bookstore
$queryadmin ="SELECT last_name, first_name, user_id FROM users";
$recordz = @mysqli_query ($dbc, $queryadmin);
while ($row = mysqli_fetch_array($recordz, MYSQLI_ASSOC)) {
echo '<tr>
<td align="left">' . $row['first_name'] . '</td>
<td align="left">' . $row['last_name'] . '</td>
<td align="left">' . $row['user_id'] . '</td>
</tr>'
;}
now i want an additional column from another table where the numbers of books each user has lend out are displayed.
So the query if nested seperately would go something like this
$query2 = mysql_query("SELECT FROM mirror3 WHERE userid='".$row['user_id']."'", $link);
$anzahl = mysql_num_rows($query2);
placing this query nested inside the while query (right after while starting) from above does not work. How to do that?
supplied argument is not a valid MySQL
result resource
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的查询是错误的。指定字段名称:
Your query is wrong. Specify a field name:
您可能可以在一个查询中执行此操作:
但是 Parkyprg 有一个观点,您需要从第二个查询中选择某些内容。
You could probably do this in one query:
But Parkyprg has a point, you need to be selecting something from that second query.