I need help regarding a thing I've been doing. So, I have stored some access data in this table:
SELECT * FROM MASTER_ROLE;
+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+
| userid | Page A | Page B | Page C | Page D | Page E | Page F | Page G | Page H | Page I |
+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 0 | 2 | 1 | 1 | 0 | 2 | 0 | 1 | 2 |
+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+
I am storing data like this because I need to give any 1 of 3 levels of access (Restricted, User and Admin) individually for different pages to different people. So, if a person is an admin for Page A, he might be restricted from Page B. Here, I have shown 0: admin, 1: user and 2: restricted.
Therefore, when a user logs in successfully, I need to send this table to the front end:
//query to retreive access rights for userid=1;
+-----------+-------+
| Page Name | Right |
+-----------+-------+
| Page A | 0 |
| Page B | 2 |
| Page C | 1 |
| Page D | 1 |
| Page E | 0 |
| Page F | 2 |
| Page G | 0 |
| Page H | 1 |
| Page I | 2 |
+-----------+-------+
This is because in the front end, I will traverse through this table using a loop and disable all the pages with access right = Restricted.
ALSO, PLEASE NOTE THAT THE QUERY NEEDS TO BE DYNAMIC SO THAT IT DOES NOT NEED TO BE CHANGED WHEN THE NUMBER OF PAGES (IE. NO. OF COLUMNS IN THE MASTER_ROLE TABLE INCREASE.
Thank you very much :)