title: Loading Datas as Tree Structure
body: <pre><code>I want sort out the data from Categories table like tree structure as given below…
  </code></pre>
  
  <p>Categories table have category with his parent id on that table….and also each categories may have a lot of child...and also each child may have lot of inner child.... I want to get all child according to that parent by dynamically…. I unable to get data beyond some level(Means Dynamically)… how to get that tree structure with all categories and his child respectively….is this possible?</p>
  
  <pre><code>![TREE STRUCTURE][1]
  
  
  From the Table 'categories' as given below...
  
  !['CATEGORIES' TABLE IMAGE][2]
  
  
    [1]: http://i.stack.imgur.com/1oW5j.png
    [2]: http://i.stack.imgur.com/dJ7ht.png
  
  
  
  my static code is
  
  $list_pcat_q = mysql_query("select * from categories where parent_id='0'");
              while($list_pcat_f = mysql_fetch_array($list_pcat_q)){
              $parent=extract($list_pcat_f);
              echo"&lt;h3&gt;&lt;a href='categories_list.php?cate_id=$cat_id'&gt;".$cat_name."&lt;/a&gt;&lt;/h3&gt;";
  
                  $list_scat_q = mysql_query("select * from categories where parent_id=$cat_id");
                  while($list_scat_f = mysql_fetch_array($list_scat_q)){
                  extract($list_scat_f);
                  echo "&lt;h4&gt;&lt;a href='categories_list.php?cate_id=$cat_id'&gt;".$cat_name."&lt;/a&gt;&lt;/h4&gt;";
  
                      $list_sscat_q = mysql_query("select * from categories where parent_id=$cat_id");
                      while($list_sscat_f = mysql_fetch_array($list_sscat_q)){
                      extract($list_sscat_f);
  
                          echo "&lt;h5&gt;&lt;a href='categories_list.php?cate_id=$cat_id'&gt;".$cat_name."&lt;/a&gt;&lt;/h5&gt;";
  
                          $list_ssscat_q = mysql_query("select * from categories where parent_id=$cat_id and final_flag='1'");
                          while($list_ssscat_f = mysql_fetch_array($list_ssscat_q)){
                          extract($list_ssscat_f);
  
                          echo "&lt;h6&gt;&lt;a href='categories_list.php?cate_id=$cat_id'&gt;".$cat_name."&lt;/a&gt;&lt;/h6&gt;";
  
                          }
  
                      }
  
                  }
  
              }
  </code></pre>