title: Display tree menu of selected parent
body: <p>Here im building a tree menu. A category is accessed by its id and its child displayed.
  my function works fine for two level menu but fails to generate level third. Third level menu should be displayed only if id of a second level item clicked. I need this function to track the path to node too. That if a third level id is given than tree should be expanded to third level. i.e. parent of the child and if that parent has a parent too.
  mySQL Table</p>
  
  <pre><code>+-------+-----------+------------+
  |  id   |  title    | parent_id  |
  +-------+-----------+------------+
  |   1   | Computers |    NULL    |
  +-------+-----------+------------+
  |   2   | Dell      |     1      |
  +-------+-----------+------------+
  |   3   | Laptops   |     2      |
  +-------+-----------+------------+
  |   4   | Desktops  |     2      |
  +-------+-----------+------------+
  |   5   | HP        |     1      |
  +-------+-----------+------------+
  </code></pre>
  
  <p>PHP code</p>
  
  <pre><code>&lt;?php
   $sql = "SELECT * FROM category";
   $statement= $db-&gt;prepare($sql);
   $statement-&gt;execute();
   $categories = array();
   $rootCategories = array();
   while ( $row = $statement-&gt;fetchObject() ) {
          $row-&gt;childs = array();
          $categories[$row-&gt;id] = $row;
          if(empty($row-&gt;parent_id)) {
                  $rootCategories[$row-&gt;id] = $categories[$row-&gt;id];
          } else {
                  $categories[$row-&gt;parent_id]-&gt;childs[] = $categories[$row-&gt;id];
          }
   }
  
    function rederTreeById($records, $id=false) {
          echo '&lt;ul&gt;';
          foreach($records as $record) {
                  if($id == $record-&gt;id) {
                          echo '&lt;li&gt;'.$record-&gt;title;
                          if(!empty($record-&gt;childs)) {
                                  rederTreeById($record-&gt;childs);
                          }
                          echo '&lt;/li&gt;';
                  } else {
                          echo '&lt;li&gt;'.$record-&gt;title.'&lt;/li&gt;';
                  }
          }
          echo '&lt;/ul&gt;';
   }
  
  
   rederTreeById($rootCategories, 1);
  ?&gt;
  </code></pre>
  
  <p>For example
  if clicked Computers then</p>
  
  <ul>
  <li>Computer
  <ul>
  <li>Dell    </li>
  <li>HP</li>
  </ul></li>
  </ul>
  
  <p>if Dell s clicked then</p>
  
  <ul>
  <li>Computer
  <ul>
  <li>Dell<br>
  <ul>
  <li>Laptops</li>
  <li>Desktops</li>
  </ul></li>
  <li>HP</li>
  </ul></li>
  </ul>