I want to implement a little "rights" management and only show fields in a resultset, that are set to public. The name of the field and if its public or private is stored in a 2nd table.
"select user.id, user.firstname, user.lastname, user.email
from users where (user.id = '30')"
Now the table rights would look like
id / user_id / fieldname / type
1 / 30 / users.lastname / private
2 / 30 / users.firstname / public
3 / 30 / users.eMail / private
4 / 31 / users.lastname / private
(...)
Is there a way to put this in one query ? My other option is to run a query and loop through with PHP which I dont think is very nice.
I have something like this in mind:
Select users.firstname if (select typ from rights where user_id = users.id and fieldname =
'users.firstname') = 'public', users.lastname if (select typ from rights where user_id =
users.id and fieldname = 'users.lastname') = 'public'
So the result will be the whole row, but the fields that are set to private will contain no data.