Welcome Guest, Not a member yet? Register   Sign In
Fatal error: Cannot use object of type CI_DB_mysql_result as array
#7

[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


Messages In This Thread
Fatal error: Cannot use object of type CI_DB_mysql_result as array - by El Forum - 09-07-2009, 08:37 AM



Theme © iAndrew 2016 - Forum software by © MyBB