I have a table having hierarchical menus like
"id" "parent_id" "name"
1 0 menu
2 1 item1
3 2 item1_1
4 1 item2
5 4 item2_1
...
...
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
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']);
}
}
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?