我想在ci中的表上打印以下数据

basically i am working on a project in table had courses id are appear and under these course id student name are appears. You can see into this image

enter image description here

the data are fetch but am not able to place perfectly. can any one help me??

<div class="container"> 
   <div class="row main-center"> 
      <div class="col-md-12">
         <h4 style="Text-align:center">Teacher Name : <span></span></h4> 
      </div>
   </div> 
   <div class="row main">
      <div class="main-login main-center"> 
         <table class="table table-dark"> 
           <thead> 
             <tr> 
              <?php foreach ($mydata as $data) {?> 
                <th scope="col"><?php echo $data->COURSE_ID?></th> 
                <!-- <th scope="col">Status</th> <th scope="col">Action</th> --> 
              <?php }?> 
             </tr> 
           </thead>
           <tbody> 
             <?php foreach ($mydata as $data) {?> 
             <tr>
                <td><?php echo $data->FIRST_NAME ." ".$data->LAST_NAME; ?></td> 
             </tr> <?php } ?>
           </tbody>
      </table>
     <?php echo $this->pagination->create_links(); ?>
  </div>



 thats my code of html 

$query = $this->db->query("
   SELECT teacher_registration.COURSE_ID, 
   student.FIRST_NAME,
   student.LAST_NAME 
   FROM teacher_registration left outer JOIN student_registration ON 
   teacher_registration.COURSE_ID = student_registration.COURSE_ID 
   left outer JOIN student ON 
   student.OEN_NUMBER = student_registration.OEN_NUMBER 
   WHERE 
   teacher_registration.REG_ID =".$id
);

thats my query which are fetched the data.

    <div class="container"> 
   <div class="row main-center"> 
      <div class="col-md-12">
         <h4 style="Text-align:center">Teacher Name : <span></span></h4> 
      </div>
   </div> 
   <div class="row main">
      <div class="main-login main-center"> 
         <table class="table table-dark"> 
           <thead> 
             <tr> 
              <?php foreach ($mydata as $data) {?> 
                <th scope="col"><?php echo $data->COURSE_ID?></th> 
                <!-- <th scope="col">Status</th> <th scope="col">Action</th> --> 
              <?php }?> 
             </tr> 
           </thead>
           <tbody> 

             <tr>
<?php foreach ($mydata as $data) {?> 
                <td><?php echo $data->FIRST_NAME ." ".$data->LAST_NAME; ?></td> 

             </tr> 
           </tbody>
      </table>
     <?php echo $this->pagination->create_links(); ?>
  </div>

loop must be inside <tr> to get out put in same line

Just iterate the table cell (td) instead if the row...

<tbody> 
  <tr>
     <?php foreach ($mydata as $data) {?> 
         <td><?php echo $data->FIRST_NAME ." ".$data->LAST_NAME; ?></td> 
     <?php } ?>
  </tr>
</tbody>