I've set up a simple rights management, based on binary addition.
Every navigation entry in my database follows this structure:
Every user has his own access level..
user = 3 (1+2 - access level) admin = 15 (1+2+4+8)
So far so good. My problem is now, selecting the corresponding fields from the table via MySQL. My first approach was to select all entries with a access_level <= the sum of the users access_level, but very soon I realized that this also includes other pages with a lower access_level.
You must use a binary AND to see if the Bit is set. you also can use a set field. it is also a bitfield with naming each bit.
AND like this:
sample - create table and fill
sample - show all rows and select some via bits