テーブルからレコード全体を取得し、それらを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()
。c_row
私は変数をc_kategorimaterial/index
and copy pasteforeach
ステートメントで送信したと思いました。何が悪かったのか ?