Query Problems
Hi! I've been having some problems with a query for a while and I just can't seem to figure it out.
I need to combine the following queries into one (below). Basically, I have two tables and I would like to combine them into one for output into html. The two tables are `categories` and `permissions`. I would like all of the categories to show and just some of the permissions (the ones that pertain) but want it to show null in the array if there aren't permissions for this user.
Here are the two queries in question:
Query 1 -
SELECT categories_id, menuname, ordering FROM categories ORDER BY ordering ASC
Query 2 -
SELECT permissions_id, user_id, category_id FROM permissions WHERE user_id = 12
Here's the output I'm looking for:
Can anybody help? I've tried LEFT JOIN, but it only pulls up the ones with the user_id in it.Code:+----------------+------------+------------+------------------+----------+--------------+ | categories_id | menuname | ordering | permissions_id | user_id | category_id | +----------------+------------+------------+------------------+----------+--------------+ | 1 | Admin | 1 | 1 | 12 | 1 | | 2 | Jobs | 2 | 2 | 12 | 2 | | 3 | About Us | 3 | NULL | NULL | NULL | +----------------+------------+------------+------------------+----------+--------------+
Oh and here's the platform, Apache 2, PHP 4.2, MySQL 3.23
Thank you in advance!!
Chris





Bookmarks