If i were to fetch my navigation items from a database for my navigation bar, like the ff: Select * FROM table WHERE linkcatagory = 'main-menu'; << this will list all the main menu items, what if one of those items has a sub-items that also has to be fetched from the database. I also declared a linkcategory for my sub-menus. So the logic is when i hovered through the main items, there sub menus will be fetched from the database as well. How can I make it work?
The code below is my sample markup but i don't think it's correct.
<?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-->