带有php的UL列表同时声明,怎么做对了?

Here is the code ...

<?php
    $query = mysql_query("SELECT * FROM subjects");
    while($fetch = mysql_fetch_array($query)){
    echo "<li>" .  $fetch["menu_name"] . "</li>";   
        echo "<ul>";
        $query = mysql_query("SELECT * FROM pages WHERE subject_id = {$fetch["id"]}");
        while($fetch = mysql_fetch_array($query)){
        echo "<li>" .  $fetch["menu_name"] . "</li>";}
        echo "</ul>";
    }?>

the problem is that it gets one "subject" and the rest of the "pages" under it ...

I want it to get all subjects and all pages under it

I hope that you understood me Thanks in advance FarrisFahad

I might be wrong. But possibly because you are using the variable $query for both of the mysql queries. Try using a different variable, such as $query1 or an other such useful name for the inner one.

You are reusing and overwriting your $query variable. After the inner while loop has looped through the result set, there's no more for the outer while to loop over.

Rename the second $query variable to something else.

What do you want to display, please include it.

the right way of displaying the data is:

<?php 
$query = "SELECT * FROM subjects";
$result = mysql_query($query);
while($row= mysql_fetch_assoc($result)):
?>
     <ul>
        <!-- field_name is the field name of the table you want to display-->
        <li><?php echo $row['field_name']?></li>
        <li><?php echo $row['field_name2']?></li>
        <li><?php echo $row['field_name3']?></li>
     </ul>
<?php endwhile; ?>

also if you need two queries, the name of the other QUERY MUST be different from the other, so if you have the code above and you want to have another query, create a code like this:

<?php 
$query2 = "SELECT * FROM pages WHERE subject_id = '$row['id']'";
$result2 = mysql_query($query2);
while($row2 = mysql_fetch_assoc($result2)):
?>
    <!-- code for fetching of data here -->
<?php endwhile; ?>