我编写的以下代码仅显示表中的最后一行。但是我需要在表格中loop
显示每个。row
模型
class Catalog_products extends CI_Model {
function Show_all_products()
{
$q = $this->db->get('printer');
foreach ($q->result() as $row)
{
$data = array();
$data['id'] = $row->id;
$data['name'] = $row->name;
}
return $data;
}
}
看法
<?php echo $id ?>
<?php echo $name ?>
控制器
public function catalog()
{
$this->load->model('Catalog_products');
$data = $this->Catalog_products->Show_all_products();
$this->load->view('catalog', $data);
}