gpt4 book ai didi

php - MySQL 尝试执行 JOINed 查询时抛出错误消息

转载 作者:行者123 更新时间:2023-11-29 08:49:14 25 4
gpt4 key购买 nike

Possible Duplicate:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result

这里是代码:

$result=mysql_query("
SELECT items.items_id,
COUNT(ratings.item_id) AS TotalRating,
AVG(ratings.rating) AS AverageRating
FROM 'items'
LEFT JOIN ratings ON (ratings.item_id = items.items_id)
WHERE ratings.item_id = '{$item_id}' ;");

echo "Error message = ".mysql_error();

while($row=mysql_fetch_assoc($result)) {
$output[]=$row;
}

这是错误:

Error message = You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''items' LEFT JOIN ratings ON (ratings.item_id = items.items_id) WHERE ' at line 4
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/content/k/i/c/kickinglettuce/html/Kickinglettuce/ratethis/get_ratings.php on line 38
null

我已根据 echo 语句确认 $item_id 是正确的响应。

最佳答案

items 位于单引号 (') 中,而不是反引号 (`) 中。

关于php - MySQL 尝试执行 JOINed 查询时抛出错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11752078/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com