title: Category Hierarchy (PHP/MySQL)
body: <p>I am trying to get my all categories and sub-categories from MySQL database in a hierarchy:</p>
  
  <p>My result should be like that (just example):    </p>
  
  <blockquote>
    <ol>
    <li>Cat A
    <ul>
    <li>Sub-Cat 1
    <ul>
    <li>Sub_Sub_Cat 1</li>
    <li>Sub_Sub_Cat 2</li>
    </ul></li>
    <li>Sub_Cat 2</li>
    </ul></li>
    <li>Cat B</li>
    <li>Cat C</li>
    <li>...</li>
    </ol>
  </blockquote>
  
  <p><strong>MySQL code:</strong></p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `categories` (
     `category_id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
     `parent_id` mediumint(8) unsigned NOT NULL DEFAULT '0' COMMENT 'for sub-categories'
    PRIMARY KEY (`category_id`)
  ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 ;
  </code></pre>
  
  <p>Simply, how can get it in a hirarchy with <strong>PHP codes</strong>?</p>