title: PHP / MySQL Adjacency List Question
body: <p>I have the following issue : imaging an adjacency list, that's been walked over with a recursion 
  coming out of a sql like this </p>
  
  <pre><code>SELECT * FROM pages as ps  ORDER BY COALESCE(child_of,page_id), page_id LIMIT x,y
  
   public static function tree(&amp;$arr, $id = NULL) {
  
      $result = array();
  
      foreach ($arr as $a) {
  
          if ($id == $a['child_of']) {
  
              $a ['children'] = self::tree($arr, $a['page_id']);
  
              $result[] = $a;
          }
  
      }
  
      return $result;
  }
  </code></pre>
  
  <p>So far, so good - with another "flattener" I am getting where I need to be. Now , here is the trick , 
  this works on "paginated" results, and what possibly can happen ( and it does ) is that the parent can be in one subset and the child in a different subset. With the recursion above is obvious that 
  the child won't make it to the tree with a missing parent. </p>
  
  <p>Any ideas on how can i solve that? 
  Help is much appreciated. </p>