How to build unlimited level of menu through PHP and mysql

Posted by Starx on Stack Overflow See other posts from Stack Overflow or by Starx
Published on 2010-05-20T07:48:45Z Indexed on 2010/05/20 7:50 UTC
Read the original article Hit count: 221

Filed under:
|
|
|

Well, to build my menu my menu I use a db similar structure like this Check this To assign another submenu for existing submenu I simply assign its parent's id as its value of parent field. parent 0 means top menu

now there is not problem while creating submenu inside another submenu

now this is way I fetch the submenu for the top menu

<ul class="topmenu">
    <? $list = $obj -> childmenu($parentid); 
        //this list contains the array of submenu under $parendid
        foreach($list as $menu) {
            extract($menu);
            echo '<li><a href="#">'.$name.'</a></li>';
        }
    ?>
</ul>

What I want to do is.

  • I want to check if a new menu has other child menu
  • and I want to keep on checking until it searches every child menu that is available
  • and I want to display its child menu inside its particular list item like this

  • Home ........

© Stack Overflow or respective owner

Related posts about php

Related posts about web-development