I need help on my code igniter app..i can’t seem to find out what’s causing the pagination not to work
here’s my controller
$limit = 15;
$uri_segment = 4;
$this->load->helper('string');
$offset = $this->uri->segment( $uri_segment );
log_message('error',date('Y-m-d H:i:s', time()));
//load
//$products = $this->Products_model->get_all();
$products = $this->Products_model->get_products($limit, $uri_segment);
//var_dump($products);
log_message('error', $products );
//pagination
$this->load->library('pagination');
$config['base_url'] = site_url('admin/products/index/');
$config['total_rows'] = $this->Products_model->count_all();
$config['per_page'] = $limit;
$config['uri_segment'] = $uri_segment;
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
//table
$this->load->library('table');
$this->table->set_empty(" ");
$this->table->set_heading('ID', 'Product','Category', 'Actions');
$i = 0 + $offset;
foreach ($products as $product){
++$i;
$this->table->add_row($product->id, $product->title, $this->Categories_model->get_by_id($product->category_id)->title,
anchor('/admin/products/update/'.$product->id,'update',array('class'=>'update')).' '.
anchor('/admin/products/delete/'.$product->id,'delete',array('class'=>'delete','onclick'=>"return confirm('Are you sure want to delete this product?')"))
);
}
$data['table'] = $this->table->generate();
//load template
$this->products_list();
$this->products_template();
$this->template->build('products/productList', $data);
here’s my model
function get_products($num, $offset) {
return $this->db->get($this->tbl_products, $num, $offset)->result();
}
it generates the links but then it doesn’t load the next set of records..any corrections on the code above?
thanks!
You should give the page to the table, not the full table. Pagination just fills the links, but doesn’t make any change on your data, it’s your responsability.
Please change:
with:
and in your model make the propper selection: