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)
MODEL
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;
}
CONTROLLER
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
UNTILL结束了num_rows,我如何进入像我的表中的mysql coz foreach将所有项目读入一行?
答案 0 :(得分:0)
通过在td
元素中放置一个foreach循环,您将所有值转储到单个单元格中。您需要在行级别循环 - 您已经在行级别。尝试:
<?php
$rows = $top_item->result();
foreach ($rows as $row) {
?>
<tr>
<td> <?php echo $row->NAMA_ITEM_INSPECTION; ?> </td>
等等。