I use codeigniter. I already have an permissions access levels `php` and `mysql` using sessions.
I want to limit the pages that can be viewed by a registered admin depending on his access level. I have in database for each admin (each `id_relation` is for a admin) as image:

![enter image description here][1]

Each of this number in above database table is a page for example: (values subpages and service columns are `json`)

in mainpage: `1` is `page 1` , `3` is `page 3`, `5` is `page 5` and ...

PHP: (I tried)
PHP Code:
    $result $this->db->get_where('access_level', array('id_relation'=>'6572242cc91f61b2f722e31ec55e3c7c'));
$data = array();
$result->result() as $row){
$data[] = $row->mainpage;        
'not access';
// out put is access 
Now How do I set permissions for `subpage` for three-row that have `mainpage 1` for own pages? for example in the above database.

In id `1` user in `mainpage` has access to page `1` and in this mainpage(page 1) he has access to pages 3 , 4 , 6 in subpage and in each of subpages he has access to service 110. (They are connected together like a chain.)

It is also for the rest of the rows.
My html is as: http://jsfiddle.net/pbNt3/ and my php for insert data is as: http://pastebin.com/HpztqSwV

How to allow user access to any of the pages (mainpage and subpages ) and services in it subpages by php?

[1]: http://i.stack.imgur.com/4itDn.png