title: Easiest way to build a tree from a list of Ancestors
body: <p>In my heart, I feel that there must be a super simple recursive solution to this, but I cannot immediately grok it.</p>
  
  <p>I have a tree stored in SQL as a closure table.  The tree looks like: (1 (2 (3), 4)), and the languages are MySQL's SQL and PHP 5.3.</p>
  
  <p>The closure table is thus:</p>
  
  <pre><code>+----------+------------+
  | ancestor | descendant |
  +----------+------------+
  |        1 |          1 | 
  |        2 |          2 | 
  |        3 |          3 | 
  |        4 |          4 | 
  |        1 |          2 | 
  |        1 |          3 | 
  |        1 |          4 | 
  |        2 |          3 | 
  +----------+------------+
  </code></pre>
  
  <p>I can query the ancestors quite easily with:</p>
  
  <pre><code> SELECT descendant AS id, GROUP_CONCAT(ancestor) as ancestors FROM
   closure GROUP BY (descendant);
  
   +----+-----------+
   | id | ancestors |
   +----+-----------+
   |  1 | 1         | 
   |  2 | 2,1       | 
   |  3 | 3,1,2     | 
   |  4 | 4,1       | 
   +----+-----------+
  </code></pre>
  
  <p>How can I easily build a tree in PHP with this data? Can I use a smarter query to pull more of the data from MySQL?</p>