gpt4 book ai didi

php - php mysql 中的 Bootstrap 导航

转载 作者:行者123 更新时间:2023-11-30 00:09:15 25 4
gpt4 key购买 nike

我之前有过导航树,如下图:

<?php               
$main=mysql_query("SELECT * FROM mainmenu WHERE aktif='Y'");

while($r=mysql_fetch_array($main)){
echo "<li><a href='$r[link]'><span>$r[nama_menu]</span></a>";
$sub=mysql_query("SELECT * FROM submenu, mainmenu
WHERE submenu.id_main=mainmenu.id_main
AND submenu.id_main=$r[id_main] AND submenu.id_submain=0 AND submenu.aktif='Y'");
$jml=mysql_num_rows($sub);
// if submenu found
if ($jml > 0){
echo "<div><ul>";
while($w=mysql_fetch_array($sub)){
echo "<li><a href='$w[link_sub]' class='parent'><span>&#187; $w[nama_sub]</span></a>";
$sub2 = mysql_query("SELECT * FROM submenu WHERE id_submain=$w[id_sub] AND id_submain!=0");
$jml2=mysql_num_rows($sub2);
if ($jml2 > 0){
echo "<div><ul>";
while($s=mysql_fetch_array($sub2)){
echo "<li><a href='$s[link_sub]'>&#187; $s[nama_sub]</a></li>";
}
echo "</ul></div></li>";
}
}

echo "</li></ul></div>
</li>";
}
else{
echo "</li>";
}
}
?>

那么我也有一个数据库,如下:

SQL

如何将导航树转化为bootstrap?提前致谢

最佳答案

我已经修改了您的代码以适应 Bootstrap

导航 Bootstrap 标记

 <ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
</ul>
</li>
</ul>

这是 php 代码

$main=mysql_query("SELECT * FROM mainmenu WHERE aktif='Y'");

while ($r = mysql_fetch_array($main)) {

$sub = mysql_query("SELECT * FROM submenu, mainmenu
WHERE submenu.id_main=mainmenu.id_main
AND submenu.id_main=$r[id_main] AND submenu.id_submain=0 AND submenu.aktif='Y'");
$jml = mysql_num_rows($sub);

$dropdown = ($jml > 0) ? 'class="dropdown"' : '';
echo "<li $dropdown><a href='$r[link]'>$r[nama_menu]";

// if submenu found
if ($jml > 0) {
echo "<b class="caret"></b><ul class="dropdown">";
while ($w = mysql_fetch_array($sub))
{
echo "<li><a href='$w[link_sub]' class='parent'><span>&#187; $w[nama_sub]</a>";
$sub2 = mysql_query("SELECT * FROM submenu WHERE id_submain=$w[id_sub] AND id_submain!=0");
$jml2 = mysql_num_rows($sub2);
if ($jml2 > 0)
{
echo "<ul $dropdown>";
while ($s = mysql_fetch_array($sub2))
{
echo "<li><a href='$s[link_sub]'>&#187; $s[nama_sub]</a></li>";
}

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

echo "</li></ul>
</li>";
}
else
{
echo "</a></li>";
}
}

关于php - php mysql 中的 Bootstrap 导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24227419/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com