I've got a group of checkboxes that the Admin can tick to provide customers privleges. During my situation, the Admin can click these checkboxes: Image on ImageShack. These checkboxes allows customers to see data for individuals nations/metropolitan areas.

I'm attempting to rack my brains to complete the folowing:

1) The proper way to place this permissions into my database 2) How you can later exercise what permissions each user is permitted

Right now, I'm considering just adding plenty of posts for every checkbox into my db and set single or there. Then check these using plenty of if functions!! This will probably be a period waster when coding.

Can there be other things I'm able to do? I appreciate any help!

You'll need the SET data type. A Collection seems a bit field where every bit includes a title:

ALTER TABLE user ADD COLUMN permissions SET(

Choosing customers that may view data for asia:

SELECT * FROM user WHERE FIND_IN_SET('Asia',permissions) > 0;

Or choosing all customers that may view Asia and Europe although not Africa:

SELECT * FROM user WHERE permissions & 40 = 40 AND !(permissions & 4)

I'd further define these constants in PHP, your code ought to be quite readable:

define('PERMISSION_ASIA', 8);
define('PERMISSION_EUROPE', 32);
# ...

# Check if user can view data for Africa
if ($user['permissions'] & PERMISSION_AFRICA) {
    # ...

# Check if user can Asia and Europe but not Africa
if ($user['permissions'] & PERMISSION_ASIA
    && $user['permissions'] & PERMISSION_EUROPE
    && !($user['permissions'] & PERMISSION_AFRICA)) {
    # ...

I'd opt for the stabilized database approach: you've got a many-to-many relationship between customers and permissions. You'll need an intersection table to keep these details.

CREATE TABLE UserPermissions (
  user_id INT NOT NULL,
  perm_id INT NOT NULL,
  PRIMARY KEY(user_id, perm_id),
  FOREIGN KEY (user_id) REFERENCES Users (user_id),
  FOREIGN KEY (perm_id) REFERENCES Permissions (perm_id)

Whenever you enter permissions for any user, enter one row for every permission:

INSERT INTO UserPermissions (user_id, perm_id) VALUES
 (1234, 1), -- for Cities
 (1234, 5), -- for continent North America
 (1234, 17); -- for country Canada

Now it's not hard to query all customers who've permission for The United States:

SELECT Users.*
FROM Users JOIN UserPermissions USING (user_id)
WHERE perm_id = 5;

You may also fetch a comma-separated listing of permissions for any given user:

SELECT user_id, GROUP_CONCAT(Permissions.Name) AS perm_list
FROM UserPermissions JOIN Permissions USING (perm_id)
WHERE user_id = 1234
GROUP BY user_id;

You might have a permissions table using the customers title after which numerous posts for every permission.

Jetski from you against filling your customers table with all of this data (because you most likely just have it inside a limited capacity), but enables you to check out each permission and find out what permissions a person has:


For Each Field
     User.Permission[Field] = Field
Next Field

As lengthy as you've a particular variables within the User structure that enables you to definitely keep an eye on permissions after they are loaded (a roadmapOrassociative array could be great for this.)