What I have:
I have a column in my table called privileges that stores a string of privileges for a user. (-1 = owner, 0 = admin, 1 = moderate comments, etc.) So I would have string like this in sql: 1,2,3.
The problem:
If I wanted to select all users that are admins AND moderators, it becomes a little tricky with LIKE conditions. Right now, If I want an admin, I just cycle through all the users search for 1 (using PHP – inefficient).
I am looking for a solution that is easily ‘plugged’ by plugin developers and is easily query-ed. My solution works, but if the users were to grow to hundreds, it could take awhile cycling through all them repeatedly just to find a certain privilege.
Does anyone have a better method or thoughts on this?
You will have a faster query if you normalize your table (create an additional table
user_privilegeswith separate record per privilege). This way you could run:and this could use an index on
privilege.You may also consider storing the privileges in a native
SETdatatype.