已经从MYSQL数据库中获取了无序列表,现在我想获取列表中每个标题的子列表,并以下拉列表结束。
困难之处在于我希望从数据库中获取子列表。
另外,它应该根据指定的外键放置。
菜单1(id = 1)
子菜单1(sub id = 1)
<ul class="subjects">
<?php
//db query
$query = 'SELECT * FROM `subjects` ';
$query .= 'WHERE visible = 1 ';
$query .= 'ORDER BY position ASC';
$subject_set = mysqli_query($connection, $query);
confirm_query($subject_set);
while ($subject = mysqli_fetch_assoc($subject_set)) { ?>
<li>
<?php
echo $subject['menu_name'];
$query = 'SELECT * FROM `pages` ';
$query .= 'WHERE visible = 1 ';
$query .= 'AND subject_id = ' . $subject['id']. ' ';
$query .= 'ORDER BY subject_id ASC';
$page_set = mysqli_query($connection, $query);
echo mysqli_error($connection);
confirm_query($page_set);
?>
<ul class="pages">
<?php
while ($page = mysqli_fetch_assoc($page_set)) {
?>
<li>
<?php echo $page['menu_name']; ?>
</li>
<?php
}
mysqli_free_result($page_set);
?>
</ul>
</li>
<?php } ?>
</ul>
菜单2(id = 2)
子菜单2(sub id = 2)
请有人帮忙。