title: PHP Categories Dropdownlist
body: <p>I've been trying a lot of algorithms, including functions inside functions, and so on... But I haven't been able to solve this, hope you can help me.</p>
  
  <p>I have a MySQL Table with categories, each category can have a parent category. Top categories are those whose parent is 0.</p>
  
  <pre><code>id   |   parent   |   name   |   desc 
  ------------------------------------------------
  1    |     0      | sportwear|  test 
  2    |     0      | bikes    |  test
  3    |     1      | shirts   |  more tests
  4    |     1      | shoes    |  ....
  5    |     3      | men      | ....
  6    |     3      | women    | .....
  </code></pre>
  
  <p>AND SO ON....</p>
  
  <p>I would like to have a SELECT element with a list like this</p>
  
  <pre><code>CATEGORIES:
  -sportwear
  -----shirts
  --------men
  --------women
  -----shoes
  -bikes  
  -morecategories
  -etc
  </code></pre>
  
  <p>And it should have all the categories, and show them with their proper depth.</p>
  
  <p>To get them All we would use something like</p>
  
  <pre><code> SELECT * FROM categories;
  </code></pre>
  
  <p>To get subcategories from a specific parent we would use something like</p>
  
  <pre><code> SELECT * FROM categories WHERE parent = PARENT-ID-HERE;
  </code></pre>
  
  <p>How can I make a PHP algorithm to build a select list like the one shown before?</p>