我按照说明从表中获取整个记录,并将它们加载到 html 表中。这是模型
private $namatabel;
public function __construct() {
parent::__construct();
$namatabel='ms_kategori_material';
}
function read()
{
$sql = $this->db->get($this->namatabel);
if($sql->num_rows() > 0)
{
foreach($sql->result() as $row)
{
$data[] = $row;
}
return $data;
}
else
{
return null;
}
}
然后使用read()
控制器上的功能
public function __construct() {
parent::__construct();
$this->load->model('m_kategorimaterial');
}
function index()
{
$data['c_row'] = $this->m_kategorimaterial->read();
//pass the c_row into the views
$this->load->view('v/vkategorimaterial', $data);
}
在视图上显示它们
<?php
$no = 1;
foreach ($c_row as $row) { ?>
<tr id="row">
<td id="no"><?php echo $no;?></td>
<td id="judul"><?php echo $row->Kode_Kategori_Material_Jasa;?></td>
<td id="kategori"><?php echo $row->Nama_Material_Jasa;?></td>
</tr>
<?php
$no++;
}
?>
但后来我收到一条错误消息,提示未定义变量c_row
和提供的参数无效foreach()
。我以为我已经通过and 复制粘贴语句发送了c_row
变量。什么地方出了错 ?c_kategorimaterial/index
foreach