Hello,

I try to create nd horizontal dynamic sub level menu, I'm blocked, could you help me a little ?

The first level seems to be ok, but after the other level does'nt work, I tried different way

you can see the code on this page with array
http://phpfiddle.org/main/code/fdaq-kejs


Code:
  // Select all entries from the menu table
  $Qmenus = $Db->prepare('select a.id, 
                                        a.link, 
                                        a.parent_id, 
                                        a.class,
                                        a.sort_order,
                                        amd.label 
                                  FROM :table_administrator_menu a,
                                      :table_administrator_menu_description amd
                                  where a.id = amd.id
                                  and amd.language_id = :language_id
                                  ORDER BY a.parent_id, 
                                           a.sort_order
                                  ');

  $Qmenus->bindInt(':language_id', $Language->getId());
  $Qmenus->execute();
?>


<!-- Navigation -->
<nav class="navbar navbar-light bg-faded">
    <ul class="nav navbar-nav">
<?php

//http://phpfiddle.org/main/code/fdaq-kejs


  $menu_parent = array();
  $menu_sub = array();
  foreach ($Qmenus as $menus) {
    if ($menus['parent_id'] == 0) {
      $menu_parent[$menus['id']] = $menus;
    } else {
      if (isset($menu_parent[ $menus['parent_id'] ])) {
        $menu_parent[ $menus['parent_id'] ]['sub_menu'][$menus['id']] = $menus['id'];
        $menu_sub[$menus['id']] = $menus;
      } else if (isset($menu_sub[ $menus['parent_id'] ])) {
        $menu_sub[ $menus['parent_id'] ]['sub_menu'][$menus['id']] = $menus['id'];
        $menu_sub[$menus['id']] = $menus;
      }
    }
  }

// level 1
  foreach($menu_parent as $key => $menus) {
    if ($menus['link'] != '') {
      echo '<li class="nav-item"><a class="nav-link" href="'. link($menus['link']) . '">' . $menus['label'] . '</a></li>';
    } else {
//      echo '<li class="nav-item">' . $menus['label'] . '</li>';
echo '
  <button class="btn btn-success dropdown-toggle" type="button" id="dropdown_1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
    ' . $menus['label'] . '
  </button>
';
    }


// level 2
    if (!is_null($menus['sub_menu'])) {
//      echo '<ul>';
      echo '
<div class="dropdown-menu" aria-labelledby="dropdown_' . $i . '">     
      ';

      foreach($menus['sub_menu'] as $second_level) {
        if ($menu_sub[$second_level]['link'] != '')  {
          echo '<span class="dropdown-item"><a  href="'. link($menu_sub[$second_level]['link']) . '">' . $menu_sub[$second_level]['label'] . '</a></span><br />';
        } else {
          echo $menu_sub[$second_level]['label'] . '<br />';
        }




// level 3
        if ($menu_sub[$second_level]['sub_menu'] != '')  {
//          echo '<ul>';
          foreach($menu_sub[$second_level]['sub_menu'] as $third_level) {
            if (!is_null($menu_sub[$third_level]['link'])) {
              echo '<li class="nav-item"><a class="nav-link" href="'. link($menu_sub[$third_level]['link']) . '">' . $menu_sub[$third_level]['label'] . '</a></li>';
            } else {
              echo '<li class="nav-item">' . $menu_sub[$third_level]['label'] . '</li>';
            }
// level 4
            if ($menu_sub[ $third_level ]['sub_menu'] != '')  {
//              echo '<ul>';
              foreach($menu_sub[ $third_level ]['sub_menu'] as $fourth_level) {
                if (!is_null($menu_sub[$fourth_level]['link'])) {
                  echo '<li class="nav-item"><a class="nav-link" href="'. link($menu_sub[$fourth_level]['link']) . '">' . $menu_sub[$fourth_level]['label'] . '</a></li>';
                } else {
                  echo '<li class="nav-item">' . $menu_sub[$fourth_level]['label'] . '</li>';

                }

              }
//              echo '</ul>';
            }
//            echo '</li>';

          }
//          echo '</ul>';

        }

//        echo '</li>';
*/
      }
//      echo '</ul>';

      echo '
</div>';

      $i = $i +1;
    }
//    echo '</li>';
  }
?>
    </ul>
</nav>