【发布时间】:2016-10-27 09:54:04
【问题描述】:
我有一个数据数组,想在表格中显示,但是表格中出现的列是根据数组数据的个数,如何让12列数组默认但是数量还在数据库中。假设表中出现了 2 个数据,但列数为 12...?
型号
function get_id($id) {
$this->db->where('my_id', $id);
$get_data = $this->db->get('mytable');
if ($get_data->num_rows() > 0) {
foreach ($get_data->result() as $data) {
$my_result[] = $data;
}
return $my_result;
}
}
控制器
public function myControllers() {
$id = $this->uri->segment(4);
$data=array('detail' => $this->mymodels->get_id($id));
$this->load->view('layout/wrapper', $data);
}
观看次数
<table>
<thead>
<tr>
<td>No</td>
<td>ID</td>
<td>Name</td>
<td>Class</td>
</tr>
</thead>
<tbody>
<?php
$no = 1;
foreach ($detail as $row) {
echo '<tr>';
echo '<td>'.$no.'</td>';
echo '<td>'.$row->id.'</td>';
echo '<td>'.$row->name.'</td>';
echo '<td>'.$row->class.'</td>';
echo '</tr>';
$no++;
}
?>
</tbody>
</table>
我希望作为这个例子
NO | ID | NAME | ClASS |
____|____ |______|_______|
1 | 001 | Paul | x |
2 | | | |
3 | | | |
4 | | | |
to 12
【问题讨论】:
-
列还是行。?
-
@noufalcep 列和默认第 12 行,虽然只有四列和行数据有 12 个
标签: php html codeigniter html-table