我在循环第二个 while 循环时遇到问题。它只会循环一次。所以我只能获取第二个循环的第一行的值。请帮我解决这个问题,我是初学者。
<ul id="navbar">
<?php
$rel = "SELECT * FROM table1 ORDER BY category";
$sql=$db->query($rel);
while($row = $sql -> fetch_array()){
?>
<li><a href="category.php?id=<?php echo $row['category_id'];?>"><?php echo $row['category'];?></a>
<ul>
<?php
$sel = "SELECT * FROM table2 WHERE category_id=".$row['category_id']." ORDER BY subcategory ASC";
$sql=$db->query($sel);
while($row1 = $sql -> fetch_array()){
?>
<li><a href="subcategory.php?id=<?php echo $row1['subcategory_id'];?>"><?php echo $row1['subcategory'];?></a></li>
<?php }?>
</ul>
</li>
<?php }?>
</ul>