I'm trying to avoid multiple calls to SQL and saving info in arrays... trying to find an elegant solution for a query...
I have two tables in my DB for controling which pages each user can reach-
user_access (user_id, page_id)
user_pages (page_id, page_name)
now I want to create a SELECT query which will give me all user_pages and for a specific user, put '1' if he can access this page and '0' if he cant in another column.
for example:
[tt]
user_access
user_id | page_id
123 | 2
262 | 2
262 | 4
262 | 5
user_pages
page_id | page_name
1 | one.html
2 | two.html
3 | three.html
4 | four.html
5 | five.html
then I want my result for SELECT for user_id=262 to look like
page_id | page_name | allowed
1 | one.html | 0
2 | two.html | 1
3 | three.html | 0
4 | four.html | 1
5 | five.html | 1
[/tt]
any ideas for a single SELECT query to do that? something with IF or CASE i guess, no?
THANKS!!!
(MySQL 3.23.56)
I have two tables in my DB for controling which pages each user can reach-
user_access (user_id, page_id)
user_pages (page_id, page_name)
now I want to create a SELECT query which will give me all user_pages and for a specific user, put '1' if he can access this page and '0' if he cant in another column.
for example:
[tt]
user_access
user_id | page_id
123 | 2
262 | 2
262 | 4
262 | 5
user_pages
page_id | page_name
1 | one.html
2 | two.html
3 | three.html
4 | four.html
5 | five.html
then I want my result for SELECT for user_id=262 to look like
page_id | page_name | allowed
1 | one.html | 0
2 | two.html | 1
3 | three.html | 0
4 | four.html | 1
5 | five.html | 1
[/tt]
any ideas for a single SELECT query to do that? something with IF or CASE i guess, no?
THANKS!!!
(MySQL 3.23.56)