title: How to display category and subcategory?
body: <p>How to display category and subcategory ?
  I have one table in DB. Row in this table looks something like this:</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `category` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `name` varchar(45) NOT NULL,
    `parent_id` int(11) NOT NULL,
    `order` int(11) NOT NULL,
    PRIMARY KEY (`id`)
  ) ENGINE=MyISAM
  </code></pre>
  
  <p>I want display category and subcategory like on this site: <a href="http://www.dealsdirect.com.au/c/baby-1/" rel="nofollow">http://www.dealsdirect.com.au/c/baby-1/</a> (menu on the left)</p>
  
  <p>My try:</p>
  
  <pre><code>&lt;?php 
  include 'Category_model.php'; 
  include 'Advert_model.php'; 
  $nr = $_GET['id']; 
  
  function show_category($nr){ 
  
  
      try 
          { 
              $pdo = new PDO('mysql:host=localhost;dbname=advert', 'root', ''); 
              $pdo -&gt; setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
  
              $stmt = $pdo -&gt; query("SELECT * FROM category where `parent_id` = $nr"); 
  
  
              echo "&lt;ul&gt;";  
  
              foreach ($stmt as $row){ 
                  echo "&lt;li&gt;&lt;a href=category_view.php?id={$row['id']}&gt; {$row['name']}&lt;/a&gt;".show_category($row['id'])."&lt;/li&gt;"; 
  
                  } 
                  echo "&lt;/ul&gt;"; 
                  //$id = $_GET['id']; 
                  } 
  
  
  
  
  
  
         catch(PDOException $e) 
                  { 
             echo 'Error!: ' . $e-&gt;getMessage(); 
  
             } 
  
     } 
  
     show_category($nr); 
  </code></pre>