Note that there are some explanatory texts on larger screens.

plurals
  1. PORecursive function behaves unexpected
    primarykey
    data
    text
    <p>I have a function where - based on parent-child id's - results are retrieved from the database. The parent-child structure can contain up to four 'levels' of hierarchy and based on a given scenario results from the deepest level should be retrieved from a given level.</p> <p>I have this function:</p> <pre><code>static public function ThisFunction($iParentId, $aResult) { $aRows = ClassName::GetAllByParentId($iParentId); for($i = 0; $i &lt; count($aRows); $i++) { $oRow = $aRows[$i]; if($oRow-&gt;Level != 'deepest_level') { return ClassName::ThisFunction($oRow-&gt;Id, $aResult); } else { $aResult[] = $oRow; } } return $aResult; } </code></pre> <p>In my framework database-calls (in this case ClassName is a Model_TableName) are made statically. ThisFunction refers to - as you can see, this function.</p> <p>The result is that results are being looped, but when for the first $aRows iteration 'deepest_level' has been processed all rows from that parent, the function stops. It is my expectation the function would go back to its recursive calls and process the other data all the way down.</p> <p>Am I overseeing something on this lazy sunday? Thanks in advance.</p> <p><strong>Edit</strong> I've tried the suggestions but I'm still stuck with my initial problem. Say I have this sample dataset:</p> <pre><code>id parent id level value ----------------------------- 1 0 highest AAA 2 1 middle BBB 3 1 middle CCC 4 2 deepest DDD 5 3 deepest EEE 6 0 highest FFF </code></pre> <p>This dataset has fewer levels, but its just to demonstrate.</p> <p>When I'm looking for the deepest values I'm expecting to get <code>DDD</code> and <code>EEE</code>. In my case I only get <code>DDD</code>. Also when I try to merge the results...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload