Member Avatar

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

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.

Member Avatar

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!