我試圖在下拉菜單中顯示的類別和子類別,我有這樣的:顯示類別和子類別的下拉菜單
<?php
$cat_query = "SELECT * FROM `categories`";
$select_categories = mysqli_query($connection, $cat_query);
while ($cat = mysqli_fetch_array($select_categories)) {
$cat_id = $cat['cat_id'];
$cat_title = $cat['cat_title'];
echo "<li>";
echo "<a href='#'>$cat_title <span class='caret'></span></a>";
$sub_query = "SELECT * FROM `sub_categories` WHERE `cat_id` = $cat_id";
$select_sub_categories = mysqli_query($connection, $sub_query);
while ($sub = mysqli_fetch_array($select_sub_categories)) {
$subcat_id = $sub['subcat_id'];
$subcat_title = $sub['subcat_title'];
echo "<ul class='dropdown-menu'><li>";
echo "<a href='#'>$subcat_title</a></li>";
echo "</ul>";
}
echo "</li>";
}
?>
它實際上是從數據庫中獲取的類別,但它無法正確顯示。
在桌面版本,它顯示是這樣的: Desktop View
在移動版本,它顯示是這樣的: Mobile View
難道我做錯了什麼? 任何幫助將不勝感激。 感謝
你想在'下拉菜單'中顯示,但是你正在使用'ul'和'li'。 – Irvin