```
    Table1 name : **class_subjects**
     +----+---------+-------+
    | ID | class_ID| Paper |
    +----+---------+-------+
    |  1 |       2 | Sub1  |
    |  2 |       7 | Sub3  |
    |  3 |       2 | Sub5  |
    |  4 |       2 | Sub2  |
    |  5 |       4 | Sub1  |
    |  6 |       7 | Sub5  |
    |  7 |       5 | Sub3  |
    |  8 |       5 | Sub2  |
    |  9 |       3 | Sub1  |
    | 10 |       2 | Sub1  |
    | 11 |       1 | Sub9  |
    +----+---------+-------+
     Table2 name : **classes**
    +----+--------------+
    | ID |  className   |
    +----+--------------+
    |  1 | Multimedia   |
    |  2 | Animation    |
    |  3 | Visual EFX   |
    |  4 | Visual Comm  |
    |  5 | Visual Arts  |
    |  6 | BCA          |
    |  7 | BSc          |
    |  8 | BA           |
    |  9 | BCom         |
    | 10 | BFT          |
    +----+--------------+
    I do have two tables with the names 'sjcc_class_subjects' and 'sjcc_classes'. 

```

In the first table column '**ClassID**' represents the second table '**ID**'.
 O/p like

```
+-----------+---------+
    | **Animation** |     |
    +-----------+---------+
    | #         | Subject |
    | 1         | Sub1    |
    | 2         | Sub5    |
    | 3         | Sub2    |
    | 4         | Sub1    |
    +-----------+---------+
    +-----+---------+
    | **BSc** |     |
    +-----+---------+
    | #   | Subject |
    | 1   | Sub3    |
    | 2   | Sub5    |
    +-----+---------+
    +-------------+---------+
    | Visual Comm |         |
    +-------------+---------+
    | #           | Subject |
    | 1           | Sub1    |
    +-------------+---------+

```

I am using the following code, but output is not displayed properly. Kindly help me to solve this. Thanks in advance. (Sorry for the poor coding).

```
   <?php
    $sjcc="SELECT classes.ID, classes.className, class_subjects.class_ID, class_subjects.paper FROM classes, class_subjects group by class_subjects.class_ID";      
    $sjcc_result    = $conn->query($sjcc);
    while($sjcc_result_fetch    = $sjcc_result->fetch_assoc()) {
    ?>
        <li>                
         <h1>BA MM <?php echo $sjcc_result_fetch['className'];?></h1>
          <table class="table">
          <thead>
          <tr>
           <th>#</th>
           <th>Subject</th>
         </tr>
         </thead>
        <?php
        while($sjcc_result_fetch2    = $sjcc_subject_result->fetch_assoc()) 
       {
        ?>
        <tbody>
         <tr>
           <td>1</td>
           <td><?php echo $sjcc_result_fetch2    ['paper_name']; ?></td>
         </tr>
         </tbody>
        <?php } ?>
        </table>
     </li>
        <?php } ?> 

```

Please help me to solve this issue, I am not finding any solution to go ahead. It would be greatful for me if some