I am creating dynamic menus and submenus in php.... Can't know where to start.... I have written all my queries but need suggestion to iterate the result set with Ul
and li
elements with it.... There may are may not be submenus for submenu and there may or may not be submenus for menus.....
Menu1
submenu1
submenu11
submenu12
submenu2
submenu21
Menu2
submenu1
submenu11
submenu12
Any suggestion....
EDIT:
Here is what i am doing,
<?php
$con=mysql_connect("localhost","root","");
$db=mysql_select_db("testt");
echo '<ul id="nav">';
$res=mysql_query("SELECT * FROM menu WHERE PARENT_ID=0");
while($row=mysql_fetch_array($res))
{
echo '<li class="top"><a href="#" class="top_link"><span>'.$row['MENU_NAME'].'</span></a></li>';
$res1=mysql_query("SELECT * FROM menu WHERE PARENT_ID=1 AND CHILD_ID=".$row['ID']."");
echo '<ul class="sub">';
while($row1=mysql_fetch_array($res1))
{
echo '<li><a href="#" class="fly">'.$row1['MENU_NAME'].'</li>';
$res2=mysql_query("SELECT * FROM menu WHERE PARENT_ID=2 AND CHILD_ID=".$row1['ID']."");
echo '<ul>';
while($row2=mysql_fetch_array($res2))
{
echo '<li><a href="#">'.$row2['MENU_NAME'].'</li>';
}
echo '</ul>';
}
echo '</ul>';
}
echo '</ul>';
?>
Here is my table,
My CSS Class doesn't seem to get applied