How to display child menu item under their parent item in php? -
i need display child menu items under corresponding parent items in php. have created mysql query unable child items under parent items.here code:
for ($i = 0; $i < count($menu); $i++) { echo'<li><a href="' . $url . $menu[$i]['id'] . '" title="' . $menu[$i]["menu_name"] . '">' . $menu[$i]["menu_name"] . '</a>'; if ($menu[$i]['parent_id'] != "0" && $menu[$i]['parent_id'] != null) { echo'<ul>'; echo'<li><a href="#" title="' . $menu[$i]["submenu_name"] . '">' . $menu[$i]["submenu_name"] . '</a></li></ul></li>'; } } mysql query: select m.id, m.menu_name, sm.parent_id,sm.submenu_name,sm.id menu m left join submenu sm on (m.id=sm.parent_id) home | courses | courses | | course-1| course 2 |
so need course-1 , course 2 under courses. please me going wrong in php code?
try this:
for ($i = 0; $i < count($menu); $i++) { echo'<li><a href="'.$url.$menu[$i]['id'].'" title="'.$menu[$i]["menu_name"].'">'. $menu[$i]["menu_name"] . '</a>'; echo'<ul>'.$menu[$i]['childs'].'</ul></li>'; }
mysql query:
select m.id, m.menu_name, group_concat(concat("<li><a href=\"#\" id=\"",sm.id,"\">",sm.submenu_name,"</a></li>")) childs menu m left join submenu sm on (m.id=sm.parent_id) group m.id
Comments
Post a Comment