title: recursive function category database
body: <p>i hoping to create a recursive function which i don't have an idea yet</p>
  
  <p>this is my code to fetch category from database</p>
  
  <pre><code>  &lt;?php
    $sql = mysql_query("SELECT * FROM categories WHERE category_parent = '1' ORDER BY lft ASC");
    while($row = mysql_fetch_array($sql)) {
    echo "&lt;li&gt;&lt;a href='/{$row['category_safe_name']}/'&gt;{$row['category_name']}&lt;/a&gt;";
    $sql2 = mysql_query("SELECT * FROM categories WHERE category_parent = '{$row['category_id']}'");
    if(mysql_num_rows($sql2) &gt; 0)
    echo "&lt;ul&gt;";
    while($row2 = mysql_fetch_array($sql2)) {
    echo "&lt;li&gt;&lt;a href='/{$row2['category_safe_name']}/'&gt;{$row2['category_name']}&lt;/a&gt;&lt;li&gt;";
    }
    if(mysql_num_rows($sql2) &gt; 0)
    echo "&lt;/ul&gt;";
    echo "&lt;/li&gt;";
    }
    ?&gt;
  </code></pre>
  
  <p>Currently This look like</p>
  
  <pre><code>Top Category (category_id = 1)
     Category
         Sub Category
  </code></pre>
  
  <p>My code works for category &amp; subcategory. What i'm planning to do is to make my code to support unlimited subcategories</p>
  
  <p>Any help and advise are welcomed.</p>
  
  <p>Thank you</p>