[eluser]mddd[/eluser]
The problem is, that you don't do anything with the result of your recursive function. The function will call itself until it reaches 'parent_id=0'. The last recursion of the function will then return the correct id. But this 'return value' goes to the previous recursion. And that recursion doesn't do anything with the value!
I think the solution is simple:
Code:
// replace this:
$this->get_upper_most_parent($parent_id,1);
// with this:
return $this->get_upper_most_parent($parent_id);
That way, every recursion returns its result to the one before. And eventually: back to the main call you make to the model.
(Note: you are making a lot of calls to the database this way. I think there are quicker methods to get the main parent. For instance: if you know te maximum depth of your pages, you could join multiple times on the same table and check the correct parent in php. You'll need only 1 call to the database and fetch 1 row to do it).