0

重複の可能性:
警告: mysql_fetch_array(): 指定された引数は有効な MySQL 結果ではありません

コードは次のとおりです。

$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

$item_id が echo ステートメントに基づいて正しい応答であることを確認しました。

4

1 に答える 1

2

itemsBACKTICKS(`) ではなく、SINGLE QUOTES (') にテーブルがあります。

于 2012-08-01T03:14:28.330 に答える