php - Arrange data retrieved by database in a HTML table using foreach -


i'm using codeigniter. pass data retrieved database view. there 5 lists must display on table each column should contain list of names generated foreach loop in view. following code of view.

 <table class="table table-hover" >     <thead>     <tr>       <th scope="col" width="20%">cameramen</th>       <th scope="col" width="30%">camera assistants</th>       <th scope="col" width="12%">technical assistants</th>       <th scope="col" width="20%">setup engineer</th>       <th scope="col" width="30%">audio operator</th>       <th scope="col" width="12%">vision operator</th>     </tr>     </thead>       <tbody>       <tr>        <?php         $index = 0;         foreach($c_list $n_key){?>             <td><?php echo $index+1; ?>             <?php echo $n_key->name; ?><br/><br/>              <?php                $index++;               }?>               </td>          <?php           $index = 0;           foreach($ca_list $n_key){?>             <td><?php echo $index+1; ?>               <?php echo $n_key->name; ?><br/><br/>               <?php                $index++;               }?>               </td>            <?php             $index = 0;               foreach($ta_list $n_key){?>                <td><?php echo $index+1; ?>                 <?php echo $n_key->name; ?><br/><br/>                  <?php                    $index++;                   }?>                   </td>               <?php               $index = 0;               foreach($se_list $n_key){?>                 <td><?php echo $index+1; ?>                 <?php echo $n_key->name; ?><br/><br/>                  <?php                    $index++;                   }?>                   </td>              <?php               $index = 0;               foreach($ao_list $n_key){?>                 <td><?php echo $index+1; ?>                   <?php echo $n_key->name; ?><br/><br/>                   <?php                    $index++;                   }?>                   </td>                <?php                 $index = 0;                   foreach($vo_list $n_key){?>                     <td><?php echo $index+1; ?>                     <?php echo $n_key->name; ?><br/><br/>                      <?php                        $index++;                       }?>                       </td>              </tr>           </tbody>         </table> 

but gives following out put.

enter image description here

i want display names line line in each column. can show me error?

to retrieve data database have written 6 function in model. same. add 1 model function here.

public function get_c_names($c) {     $cdata = array();     foreach($c $row) {         $cdata[] = $row->employee_id;     }      $this->db->select('employee.name');     $this->db->from('employee');     $this->db->where('employee.id in ('.implode(", ",$cdata).')');     $query=$this->db->get();     return $query->result(); } 

in controller call function following code , passed view follows. 6 functions have same pattern. post 1 of them.

 $name['c_list']  = $this->employee_model->get_c_names($c);  $this->load->view('team_view',$name); 

<table class="table table-hover" > <thead> <tr>   <th scope="col" width="20%">cameramen</th>   <th scope="col" width="30%">camera assistants</th>   <th scope="col" width="12%">technical assistants</th>   <th scope="col" width="20%">setup engineer</th>   <th scope="col" width="30%">audio operator</th>   <th scope="col" width="12%">vision operator</th> </tr> </thead>   <tbody>     <?php     for($x = 0 ; $x < count($c_list) ; $x++){         echo '<tr>';           echo '<td>'. $c_list[$x] .'</td>';           echo '<td>'. $ca_list[$x] .'</td>';           echo '<td>'. $ta_list[$x] .'</td>';           echo '<td>'. $se_list[$x] .'</td>';           echo '<td>'. $ao_list[$x] .'</td>';           echo '<td>'. $vo_list[$x] .'</td>';         echo '</tr>';     }    ?>        </tbody>     </table> 

if lists have same length solution.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -