title: Algorithm for listing a tree hierarchy for categories in the same table
body: <p>I have a SQL table <code>tbl_categories</code> with these fields: </p>
  
  <pre><code>id , parent , title
  </code></pre>
  
  <p>for instance, the table may contain this information:</p>
  
  <pre><code>id   parent  title
  1     0      the main item
  2     1      first sub item
  3     1      second sub item
  4     2      first sub sub item 
  5     3      second sub sub item
  </code></pre>
  
  <p>for example: 1 is the top category, 2 and 3 are children of 1, 4 is child of 2 and 5 is child of 3.</p>
  
  <p>I want to list this information like a tree structure using PHP, like this:</p>
  
  <pre><code>- 1. the main item
   -- 2.first sub item
    ---4.first sub sub item
   -- 3. second sub item
    ---5.second sub sub item
  </code></pre>
  
  <p>and consider to add the "-"'s according to the level of the item in the tree.</p>
  
  <p>So the question is: what is an appropriate algorithm for this task?</p>