Welcome Guest, Not a member yet? Register   Sign In
Model problem
#10

[eluser]theprodigy[/eluser]
Quote:foreach ($res->result() as $r) {
// push found result onto existing tree
$tree[$r->id] = $r;
// create placeholder for children
$tree[$r->id]['children'] = array();
// find any children of currently found child
$tree = $this->generateTree($r->id, $tree[$r->id]['children']);
}

I think the problem lies in:
Code:
// push found result onto existing tree
$tree[$r->id] = $r;
// create placeholder for children
$tree[$r->id]['children'] = array();

$r is an object. So
Code:
$tree[24] = stdObject()
$tree[25] = stdObject()
etc

Then you turn around and try to add another dimension onto the array with the next line
Code:
$tree[$r->id]['children'] = array();

You were getting a different error when you were using result_array(), then you are now with result().

Try changing back to result_array()
Change your if to
Code:
if ($res->num_rows() > 0) {...}

and remove the '$tree =' from
Code:
$tree = $this->generateTree($r->id, $tree[$r->id]['children']);

It's also bad form to have an optional parameter in front of a required parameter in a function declaration
Code:
function generateTree( $parentid = 0, &$tree ){...}
should be
Code:
function generateTree( &$tree, $parentid = 0 ){...}


Messages In This Thread
Model problem - by El Forum - 12-09-2009, 09:51 AM
Model problem - by El Forum - 12-09-2009, 09:57 AM
Model problem - by El Forum - 12-09-2009, 11:36 AM
Model problem - by El Forum - 12-09-2009, 11:47 AM
Model problem - by El Forum - 12-09-2009, 02:35 PM
Model problem - by El Forum - 12-09-2009, 02:54 PM
Model problem - by El Forum - 12-10-2009, 12:16 AM
Model problem - by El Forum - 12-10-2009, 12:21 AM
Model problem - by El Forum - 12-10-2009, 12:29 AM
Model problem - by El Forum - 12-10-2009, 12:46 AM
Model problem - by El Forum - 12-10-2009, 12:54 AM
Model problem - by El Forum - 12-10-2009, 12:59 AM
Model problem - by El Forum - 12-10-2009, 01:15 AM
Model problem - by El Forum - 12-10-2009, 01:23 AM
Model problem - by El Forum - 12-10-2009, 01:26 AM
Model problem - by El Forum - 12-10-2009, 01:30 AM
Model problem - by El Forum - 12-10-2009, 02:35 AM
Model problem - by El Forum - 12-10-2009, 08:28 AM
Model problem - by El Forum - 12-10-2009, 08:47 AM
Model problem - by El Forum - 12-10-2009, 09:43 AM
Model problem - by El Forum - 12-10-2009, 11:41 AM
Model problem - by El Forum - 12-10-2009, 12:20 PM
Model problem - by El Forum - 12-10-2009, 02:09 PM
Model problem - by El Forum - 12-10-2009, 02:29 PM
Model problem - by El Forum - 12-10-2009, 03:01 PM
Model problem - by El Forum - 12-10-2009, 05:58 PM
Model problem - by El Forum - 12-10-2009, 07:23 PM
Model problem - by El Forum - 12-10-2009, 08:53 PM
Model problem - by El Forum - 12-11-2009, 01:00 AM
Model problem - by El Forum - 12-11-2009, 01:07 AM
Model problem - by El Forum - 12-11-2009, 02:52 AM



Theme © iAndrew 2016 - Forum software by © MyBB