我正在使用PHP,Mysql和bootstrap制作动态菜单。问题在于它正在向每个子元素添加下拉类:
<ul class="nav navbar-nav">
<li class="open"><a href="#" class="has-submenu highlighted">DEMO<span
class="sub-arrow">...</span></a>
<ul ''="" class="sm-nowrap" style="display: block; width: auto; top: auto;
left: 0px; margin-left: 0px; margin-top: 0px; z-index: 3; min-width: 200px;
max-width: 400px;">
<li><a href="DEMO.php?id=20&page=1" class="has-submenu">DEMO<span
class="sub-arrow">...</span></a>
<ul 'class="dropdown-menu' "></ul>
</li>
<li><a href="DEMO.php?id=22&page=1 " class="has-submenu ">DEMO<span
class="sub-arrow ">...</span></a>
<ul ''=" "></ul>
</li>
<li><a href="DEMO.php?id=19&page=1 " class="has-submenu ">DEMO<span
class="sub-arrow ">...</span></a>
<ul ''=" ">
</ul>
</li>
<li><a href="DEMO.php?id=25&page=1 " class="has-submenu ">DEMO<span
class="sub-arrow ">...</span></a>
<ul ''=" ">
</ul>
</li>
</ul>
</li>
</ul>
当我使用引导程序时,我想要的结果类型是
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Page 1
<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Page 1-1</a></li>
<li><a href="#">Page 1-2</a></li>
<li><a href="#">Page 1-3</a></li>
</ul>
</li>
</li>
function get_menu_tree($parent_id)
{
global $con;
$menu = "";
$sqlquery = " SELECT * FROM tbl_menu where parent='" .$parent_id . "' order by sort";
$res=mysqli_query($con,$sqlquery);
$a="";
while($row=mysqli_fetch_array($res,MYSQLI_ASSOC))
{
if($a==$row['parent']){$cl=null;}else{ $cl="class=dropdown-menu";
}$a=$row['parent'];
$menu .="<li ><a href='".$row['link']."'>".$row['label']."</a>";
$menu .= "<ul '".$cl."'>".get_menu_tree($row['id'])."</ul>"; //call recursively
$menu .= "</li>";
}
return $menu;
}