0

I wan't to check if a user is listed as permitted in a particular group. How'd you do that?
Should I do something like this?

group_id | permitted_users
1        | mark,jon
2        | maria,warren,mila

now I gotta retrieve the value of permitted_user column of a specific group then separate every name so that I can compare if the logged in user is permitted in that group. I mean if I want to check is "mila" is permitted in group 2 then I gotta retrieve group two's permitted_user's values then separate em. But how to do that? Using explode and array? Or I can go with expressions? Just gimme the direction, I will do the rest :)

Any other idea is most welcome! Like using space instead of comma in permitted_user.

Thanks in advance

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by TechySafi
0

Do it in an orderly fashion with one table for users, one table for permissions, one table which links both and a group_concat function which helps you with your string search.
If you stick with your solution, just do a preg_match for '/(^|,)mila(,|$)/' in row 2 to check if mila is permitted in group 2.

0

@smantscheff
I already have a table for users, gonna create one for group id,names etc. So you are suggesting to create one more table for permissions? Gimme some clue how that table should look like?

Though I'm sure I can get my script working with the 2nd trick but I wan't to try the 1st one too :)

Anyway thanks for helping!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.