Reputation: 109
I have a query to select fields from 3 tables and join them together but I keep getting
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in....
Here is my table structure:
quote (id, name) categories (id, category_name, category_slug) in_category (id, quote_id, category_id)
and here is my query
$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'
");
Anything I run will end up to be an error with this query so surely there is something wrong I'm doing here - Could you please help me with this?
Upvotes: 1
Views: 29
Reputation: 44844
Get rid of single quotes for alias names in the query.
So it should be something as
categories.id AS category_id,
.......
Also use explicit 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'
Upvotes: 1