我有一个查询从3个表中选择字段并将它们连接在一起,但我一直在
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in....
这是我的表结构:
引用(id,name) 类别(id,category_name,category_slug) in_category(id,quote_id,category_id)
这是我的查询
$select_tags=mysql_query("SELECT
categories.id AS 'category_id',
categories.category_name AS 'categories.category_name',
categories.category_slug AS 'categories.category_slug',
in_category.category_id,
in_category.quote_id,
from categories, in_category
WHERE in_category.quote_id = '$quotes_id'
");
我运行的任何内容最终都会导致此查询出错,所以我确实在这里做错了 - 你能帮我解决这个问题吗?
答案 0 :(得分:1)
在查询中删除别名的单引号。
所以它应该是
categories.id AS category_id,
.......
也使用显式JOIN
SELECT
categories.id AS category_id,
categories.category_name AS categories_category_name,
categories.category_slug AS categories_category_slug,
in_category.category_id,
in_category.quote_id
from categories
JOIN in_category on in_category.category_id = categories.id
WHERE in_category.quote_id = '$quotes_id'