foreach 在 Codeigniter 中将所有项目读入一行


foreach is read all the item into a row in codeigniter

mysql> SELECT * FROM `db_depo`.`tb_item_inspection_report` a WHERE a.TIPE= 'T'  LIMIT 1000;
+---------------------------------+-----------------------+------+--------------------+
| NAMA_ITEM_INSPECTION            | NOMOR_ITEM_INSPECTION | TIPE | ID_ITEM_INSPECTION |
+---------------------------------+-----------------------+------+--------------------+
| Protection Box Cover            | 1                     | T    |                  1 |
| Manhole LID, Fastening Bolts    | 2a                    | T    |                  2 |
| Manhole Gasket                  | 2b                    | T    |                  3 |
| PV Valve / Flame Trap / Gauge   | 3a                    | T    |                  4 |
| Rupture Disc                    | 3b                    | T    |                  5 |
| Loading Port                    | 4a                    | T    |                  6 |
| Top Operated Valve              | 5                     | T    |                  7 |
| Dipstick                        | 6                     | T    |                  8 |
| Air Line Valve (Ball Butterfly) | 7                     | T    |                  9 |
| Calibration Chart               | 8                     | T    |                 10 |
| Walkway                         | 9                     | T    |                 11 |
| Syphone Tube/Butterfly          | 4b                    | T    |                 12 |
+---------------------------------+-----------------------+------+--------------------+
12 rows in set (0.00 sec)

public function get_top_inspection_detail() {
    $query = $this->db->query('SELECT a.* FROM `db_depo`.`tb_item_inspection_report` a where a.TIPE = "T" ORDER BY `ID_ITEM_INSPECTION` ASC LIMIT 1000;');
    return $query;
}

控制器

public function menu_container() {
    $this->load->library('csvreader');
    $data = array('halaman' => 'Data Container',
        'last_cargo' => $this->m_surveyor->get_all_last_cargo(), //BUAT LAST CARGO,
        'top_item' => $this->m_surveyor_item_inspection->get_top_inspection_detail(),
        'bottom_item' => $this->m_surveyor_item_inspection->get_bottom_inspection_detail(),
        'detail_condition' => $this->m_surveyor_item_detail_inspection->get_all(),
        ); 

    $main_view = $this->load->view('surveyor/v_container', $data, TRUE);
    echo $main_view;
}

视图

<table class="table ">
   <thead>
      <tr>
         <th style="width: 70%">Item</th>
         <th style="width: 20%">Kondisi</th>
         <th style="width: 10%">Act</th>
      </tr>
   </thead>
   <tbody>
      <?php
        $rows = $top_item->num_rows();                        
         for ($j = 0; $j < $rows + 1; $j++) {
        ?>   
            <tr>
               <td>
                 <?php
                    foreach ($top_item->result() as $v) {
                       echo $v->NAMA_ITEM_INSPECTION;
                  }
                 ?>
               </td>
               <td>
                  <select class="form-control" name="list2_kondisi_1" id="list2_name_1">
                  <option>Choose...</option>
                  <?php
                      foreach ($detail_condition as $v) {
                           echo '<option value =' . $v->ID_ITEM . ' >' . $v->ALIAS . '    - ' . $v->NAME_ITEM . '</option>';
                      }
                  ?>
                </select>
              </td>
              <td><input type='checkbox'></td>
             </tr>   
           <?php } ?>
        </tbody>
      </table>

我想把它表示成 html 表格,就像我在 mysql 中的表格一样;根据我的视图代码,我得到了这个:

Protection Box CoverManhole LID, Fastening BoltsManhole GasketPV Valve / Flame Trap / GaugeRupture DiscLoading PortTop Operated ValveDipstickAir Line Valve (Ball Butterfly)Calibration ChartWalkway 
Protection Box CoverManhole LID, Fastening BoltsManhole GasketPV Valve / Flame Trap / GaugeRupture DiscLoading PortTop Operated ValveDipstickAir Line Valve (Ball Butterfly)Calibration ChartWalkway 

直到num_rows年底,我怎样才能像我的表一样进入mysql coz foreach将所有项目读成一行?

通过在 td 元素中放置一个 foreach 循环,您可以将所有值转储到单个单元格中。您需要在行级别循环 - 您已经这样做了。尝试:

   <?php
    $rows = $top_item->result();                        
     foreach ($rows as $row) {
    ?>   
         <tr>
             <td> <?php echo $row->NAMA_ITEM_INSPECTION; ?> </td>

等等。