The following code I wrote is only displaying the last row in the table. However I need to loop and display each row in the table.
MODEL
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;
}
}
VIEW
<?php echo $id ?>
<?php echo $name ?>
CONTROLLER
public function catalog()
{
$this->load->model('Catalog_products');
$data = $this->Catalog_products->Show_all_products();
$this->load->view('catalog', $data);
}
Model:
Controller:
View: