Function won't run recursively within class

I have the following function…

		function rebuild_tree($parent = 0, $left = 1) {   

			$right = $left + 1;   
			$this->DB->build( array(	'select' => join(',', $this->getFields()), 
														'from' => $this->table,
														'where' => $this->fields['parent'] . ' = ' . $parent	
											 )		);

            while ($row = $this->DB->fetch()) {

			   $right = rebuild_tree($row['category_id'], $right);   
			$this->$db->update( $this->table, array( 'lft' => $left, 'rgt' => $right ), $this->fields['id'] . ' = ' . $parent );

			return $right + 1;   

which I’m trying to run recursively in my class but I’m getting the following error.

Call to undefined function rebuild_tree() in

I’ve tried calling the function within the function using $this->rebuild_tree, and also $this->categories->rebuild_tree() both with no joy.

Any ideas?

$right =[B] $this->[/B]rebuild_tree($row['category_id'], $right);


Tried that mate same error.

Hm, can you post the object and some code representing context?

I am having no issues with any of the other methods it’s just something about that recursive call in rebuild_tree() I can’t figure out.

OK nevermind I’ve solved it I was looking at the wrong line number :slight_smile: it was a problem with $this->$db->update. should have been $this->DB->update

It’s thrown up something else now but at least that’s out of the way. Thanks


Glad to hear it Andrew.