I have this JavaScript code that allows me to create a horizontal menu with sub menus like so:
<ul id="menu">
<li>Menu 1
<ul>
<li>Sub Menu 1</li>
</ul>
</li>
</ul>
I can create as many sub menus as I want, the problem is I'm using PHP to grab the links from a MySQL database and don't know how I can dynamically build these sub menus without manually checking a sub menu over and over again. For example in the MySQL table:
Fields: Menu_ID Menu_Name Menu_Link Menu_ParentID
So menu ID is just an auto increment and the menu_parentid allows me to assign a sub menu name/link to a parent menu. But in order to do it I currently do this for 2 sub menu checks:
$query = "SELECT * FROM site_menu WHERE Menu_ParentID = 0";
foreach($query AS $q)
{
//run through the results
$query2 = "SELECT * FROM site_menu WHERE Menu_ParentID = $q['id']";
foreach($query2 AS $q2)
{
//run through the results
}
}
As you can see I have to query twice to get just the first sub menu, what if there is a third sub menu? Do I have to run 3 queries? Any suggestions?