PHP/MySQL Navigation Menu

前端 未结 2 1051
后悔当初
后悔当初 2021-01-27 13:04

I\'m trying to create a function for a hierarchical navigational menu bar.

I want to be able to have something like this...

2条回答
  •  情歌与酒
    2021-01-27 13:31

    UPDATE:

    Try this:

    function build_navbar($pid, $sub=0)
    {
        global $db;
    
        $class = $sub ? "sub" : "navigation";
    
        $menu_build = "
      \n"; $query = $db->simple_select("navbar", "*", "pid='".$pid."'"); while($menu = $db->fetch_array($query)) { $menu_build .= "
    • ".$menu['title']."\n"; // build child links $menu_build .= build_navbar($menu['id'],1); } $menu_build .= "
    "; return $menu_build; }

    What we are doing here, is allowing each function to build a

    • group, the $sub variable will determine what the ID of the
        will be, allowing you to theme each ul differently.


        EDIT:

        I found it!

        this line

        build_navbar($menu['id'],1);
        

        needs to be changed to this:

        $menu_build = build_navbar($menu['id'],1);
        

        It looks like it should work to me.

        What I would do is add some echo statements displaying the SQL query that is being executed each time, then you can copy that into phpmyadmin (or what ever db browser you use). See if it also returns a null result. If it does, there might be something wrong with your data as well.

        so for example:

        echo "SELECT FROM navbar * WHERE pid='$pid' ORDER_BY disporder;
        ";

提交回复
热议问题