I wrote this function for parent/child relationship. 0 means it is the root parent. This works on the first root parent properly but exits after it runs down the first root parents tree. How do I fix it so after its done with the first root parent it will do the same for the other root parents?
Thanks,
-Danny
function _role_tree($roles, $parent = 0, $output = '', $extender = '', $x = 0)
{
if($x>100) die('infinate loop error');
foreach($roles as $row)
{
if($row['parent'] == $parent)
{
$role_permission_names = '';
$x++;
$permissions = explode(',',$row['perm']);
if(count($permissions)>0)
{
$this->db->select('name');
$this->db->from('permissions');
foreach($permissions as $permission)
{
$this->db->orwhere(array('pid' => $permission));
}
$permission_result = $this->db->get();
if($permission_result->num_rows() > 0)
{
foreach($permission_result->result() as $perm)
{
$role_permission_names .= $perm->name.', ';
}
}
}
$output .= $extender.$row['rid'].' - '.$row['name'].' - '.$role_permission_names.'<br />';
$output = $this->_role_tree($roles, $row['rid'], $output, $extender.' ', $x);
}
}
return $output;
}
Say I should get something like
X
--X
----X
----X
-------X
X
--X
X
X
--X
-----X
But my function will only produce
X
--X
----X
----X
-------X