title: how to get the hierarchical menu from mysql
body: <p>I have a table having hierarchical menus like</p>
  
  <pre><code>"id" "parent_id" "name"
  1 0 menu
  2 1 item1
  3 2 item1_1
  4 1 item2
  5 4 item2_1
  ...
  ...
  </code></pre>
  
  <p>and I have 100s of menu items here. In order to get all items in an array I have to write a recursive function like this</p>
  
  <pre><code>getmenu function(parent_id = 1)
  {
    $items = mysql_query("SELECT id FROM table WHERE parent_id = " + parent_id);
    while ($item = msyql_Fetch_assoc($items)) {
      ...here I put them in array and call recursive function again to get sub items...
      getmenu($item['id']);
    }   
  }
  </code></pre>
  
  <p>but this executes 100s of queries. Is this the best way to do this, to get hierarchical menus from database? Does this way loads mysql much?</p>