so i been messing around with php to find a way to generate menus using php *im bored, so yeah better do something*
anyway i decided to do it this way
function menu() {
include "config.php";
$mainMenu = mysqli_query($con, "SELECT * FROM `main-menu`") or die('Error: ' . mysqli_error($con));
if($mainMenu){
?>
<ul>
<?php
while($mainRow = mysqli_fetch_assoc($mainMenu)){
$menuId = $mainRow['id'];
$commonName = $mainRow['actualName'];
$menuName = $mainRow['name'];
$menuTags = '<li><a href="' . $menuName . '">' . $commonName;
echo $menuTags;
}
// check if there's any submenus
$subMenu = mysqli_query($con, "SELECT * FROM `sub-menu` WHERE `sub-id`=$menuId") or die('Error: ' . mysqli_error($con));
if($subMenu){
while($subRow = mysqli_fetch_assoc($subMenu)){
$subId = $subRow['sub-id'];
$subName = $subRow['sub-name'];
$subConame = $subRow['actualNames'];
$subMain = $subRow['main-menu-id'];
$actualMenu = '<ul>';
$actualMenu .= '<li><a href="' . $subName . '">' . $subConame . '</li>';
$actualMenu .= '</ul></li>';
echo $actualMenu;
}
}
}
?>
</ul>
<?php
}
?>
i was wonder if there is another way of doing this, because im only getting one of the sub menu instead of both of them
so currently the menu looks like this
Home
Services
Service 1
it suppose to look like this instead
Home
Services
Service 1
Service 2
any idea of what im doing wrong? as always your response is appreciated greatly