There is a relation of employee and manager in mysql
table which is stored as Adjacency List Model Employee has only one manager and manager have many employees if value of manager is empty that means employee without manager
relation
employee (1 to 1) manager
employee (many to 1) manager
employee manager
10 11
15 10
9 15
6 0
I want to depth of manager like for
11 depth is 3
for 10 depth is 2
for 15 depth is 1
for 6 depth is 0
......
......
.......
How can i achieve this using php below is my incomplete logic.
<?php
get_level(11) // 3
get_level(10) // 2
get_level(15) // 1
get_level(6) // 0
function get_level($level){
$this->db->get_where('manager_user', array('manager_no' => $level))
->result_array()
// logic
return no; //3 for 11
}
?>
Can some one help me in this. If any one provide me the solution with mysql function this will be also helpful for me data stored in mysql multilevel hierarchy.
Edit : I edit my question as suggested by @sintakonte.
Step taken by me to solve the issue - first i changed my table structure from The Adjacency List Model
after that this class helped me to achieve the desired result