This is my pagination code.When I click 'next' button it displaying the next page with remaining product images,but if I click 'previous' its showing the empty page.The same code I applied for another page pagination its working fine but its not working for this page.
Controller
public function onSectorClick1() {
$id = $_GET["id"];
$this->session->set_userdata('subcategory2_id', $_GET['id']);
$this->session->set_userdata('subcategory2_name', $_GET['name']);
$this->onSectorClick1Copy();
}
public function onSectorClick1Copy() {
$data['ListMenuLevel1'] = $this->Categories_model->listsector1();
$config = array();
$config["base_url"] = base_url() ."index.php/welcome/onSectorClick1Copy";
$total_row = $this->productdisplay_model->subproductlist_count($this->session->userdata('subcategory2_id'));
$config['total_rows'] = $total_row;
$config['per_page'] = 20;
$config['uri_segment'] = 3;
$config['use_page_numbers'] = TRUE;
$config['num_links'] = 1;
$config['cur_tag_open'] = ' <a class="current">';
$config['cur_tag_close'] = '</a>';
$config['next_link'] = 'Next';
$config['prev_link'] = 'Previous';
$this->load->library('pagination');
$this->pagination->initialize($config);
$page = ($this->uri->segment(3) != '' ? $this->uri->segment(3) : 1);
$offset = (($config['per_page']) * ($page - 1));
$limit = $config['per_page'] * $page ;
$data['sub2products'] = $this->productdisplay_model->sub2Productsmenu($this->session->userdata('subcategory2_id'),$limit, $offset);
$str_links = $this->pagination->create_links();
$data["links"] = explode(' ', $str_links);
$this->load->view('subproductlist', $data);
}
Model
public function subproductlist_count($id) {
$this->db->select('*');
$this->db->from('sub2_category');
$this->db->where('sub1_categoryid_fk', $id);
$this->db->order_by("sub2_category.sub1_categoryid_fk ");
$query = $this->db->get();
return $query->num_rows();
}
public function sub2Productsmenu($id,$limit, $offset){
$this->db->select('*');
$this->db->from('sub2_category');
$this->db->where('sub1_categoryid_fk', $id);
$this->db->order_by("sub2_category.sub1_categoryid_fk ");
$this->db->limit($limit, $offset);
return $this->db->get()->result();
}
View
<div class="center">
<ul class="pagination">
<?php
foreach ($links as $link) {
echo "<li>" . $link . "</li>";
}
?>
</ul>
</div>