[eluser]MEM[/eluser]
Thanks again.
Sorry, I thought I have post it all...
I'm not using result() or anything, I'm just using the absolutly fundamental query(). It happens that this query returns an object.
Should I grab this returned query object, and use result_array() to transform into an array, and then use this code again?
Isn't there an easy way for changing the for loop to have the same effect, but working with objects?
Here is the full code:
Code:
public function getSubCategorias($id_cat,$intDepth=2)
{
$strSQL = 'SELECT c.id_cat,c.nome_cat,c.parent_id_cat FROM categoria c';
$arrQuery = $this->db->query($strSQL);
return $this->_parseResultTree($id_cat,$arrQuery,$intDepth, $intRunner=0);
}
private function _parseResultTree($intParentId,&$arrRows,$intDepth,$intRunner)
{
// stop at this depth
if($intDepth == $intRunner)
{
return array();
}
$arrChildren = array();
for($i=0;$i<count($arrRows);$i++)
{
if($intParentId == $arrRows[$i]->parent_id_cat) {
$arrChildren = array_merge($arrChildren,array_splice($arrRows,$i--,1));
}
}
$intChildren = count($arrChildren);
if($intChildren != 0)
{
for($i=0;$i<$intChildren;$i++)
{
$arrChildren[$i]['children'] = parse_into_tree($arrChildren[$i]['id_cat'],$arrRows,$intDepth,$intRunner++);
}
}
return $arrChildren;
}
Please advice,
Márcio