$node = $this->get_node($root);
if($node == false)
return false;
// query
$query = $this->db->query('SELECT * FROM '.$this->tree_table.
' WHERE '.$this->left_col.' BETWEEN '.$node[$this->left_col].
' AND '.$node[$this->right_col].
' ORDER BY lft ASC');
$right = array();
$result = array();
$current =& $result;
$stack = array();
$stack[0] =& $result;
$lastlevel = 0;
foreach($query->result_array() as $row){
// go more shallow, if needed
if(count($right)){
while($right[count($right)-1] < $row[$this->right_col]){
array_pop($right);
}
}
// Go one level deeper?
if(count($right) > $lastlevel){
end($current);
$current[key($current)]['children'] = array();
$stack[count($right)] =& $current[key($current)]['children'];
}
// the stack contains all parents, current and maybe next level
$current =& $stack[count($right)];
// add the data
$current[] = $row;
// go one level deeper with the index
$lastlevel = count($right);
$right[] = $row[$this->right_col];
}
return $result;
}
You prolly remember that one, i try to think about the best way to sort those by title by recursive sub indeed.
You work on that kind of sorting with tree2array already ?