I have a set of checkboxes that an Admin can tick to give users privleges. In my case, the Admin can click these checkboxes: Image on ImageShack. These checkboxes will allow users to view data for those countries/cities.
http://img205.imageshack.us/img205/4170/screenshotao.png
I am trying to rack my brains to do the folowing:
1) How to best insert this permissions into my database
2) How to later work out what permissions each user is allowed
At the moment, I am thinking of just adding lots of columns for each checkbox into my db and put a 1 or 0 there. Then check these using lots of if functions!! This is going to be a time waster when coding.
Is there anything else I can do? I appreciate any help!
You need the SET data type. A SET is more or less a bit field where each bit has a name:
Selecting users that can view data for asia:
Or selecting all users that can view Asia and Europe but not Africa:
I would further define these constants in PHP, then your code should be quite readable: