如果我要从数据库中为导航栏获取导航项,例如 ff: Select * FROM table WHERE linkcatagory = 'main-menu'; << 这将列出所有主菜单项,如果其中一项具有也必须从数据库中获取的子项怎么办。我还为我的子菜单声明了一个链接类别。所以逻辑是当我悬停在主要项目上时,也会从数据库中获取子菜单。我怎样才能让它工作?
下面的代码是我的示例标记,但我认为它不正确。
<?php include "includes/config.php";
$sql = "Select * FROM sites WHERE site_category = 'main-menu'";
$result = mysql_query($sql);
?>
<header>
<a href="index.php" class="logo"><h1>Website</h1></a><!--LOGO-->
<div id="gutter"></div><!--gutter-->
<nav>
<ul id="menu">
<?php while($record = mysql_fetch_array($result)){
$sitename = $record['site_name'];
$sitelink = $record['site_link'];
if($sitename == 'products'){
?>
<li><a href="<?= $sitelink ?>" onMouseOver=""><?= $sitename ?></a>
<ul class="submenu">
<?php
$sql = "Select * FROM sites WHERE
site_category = 'sub-menu'";
$result = mysql_query($sql);
while($record =
mysql_fetch_array($result)){
?>
<li><a href="<?= $sitelink ?>"><?=
$sitename ?></a></li>
<?php
}//while close
?>
</ul>
</li>
<?php
}else{
echo "<li><a href=".$record['site_link'].">".$record['site_name']."
</a></li>";
}
}//while close?>
</ul><!--menu-->
</nav><!--NAV-->
</header><!--HEADER-->