public function get_children($id)
{
$query = $this->db->query("SELECT
@last_id := id AS id,
parent_id,
FIO,
@depth := IF(parent_id = ".$id.", 1, @depth + 1) AS depth,
@first := IF(id = ".$id.", 'first', null) AS first
FROM
users
FORCE INDEX (index_parent_id, PRIMARY, index_both),
(SELECT @last_id := ".$id.", @depth := -1) vars
WHERE id = ".$id." OR parent_id = @last_id OR parent_id = ".$id."
");
return $query;
}
How can i increase the level depth of children nodes using the adjacent-model-list and this query, by now it gives me the root parent(selected by id in the function) and their children, but not deeper, any ideas?
foreach($query->result() as $q){
if($q->first == 'first')
{
$parent_id = $q->parent_id;
break;
}
}
function print_list($array, $parent=0) {
print "<ul>";
foreach ($array as $row) {
if ($row->parent_id == $parent) {
print "<li>$row->FIO";
print_list($array, $row->id); # recurse
print "</li>";
} }
print "</ul>";
}
echo print_list($query->result(), $parent_id);
then I render it in the view file...please help or any advices about what to change or see to increase the depth of the mysql query.