Welcome Guest, Not a member yet? Register   Sign In
Pagination problem

can someone help me with pagination?
I'm currently using the Pagination Class and when I use $config['use_page_number'] = TRUE it's not working properly
is display the data but incorrect. it uses the URI Segment above as offset.
example in page 1 (base_url/controller/method) it doesn't have any URI segment so it displays properly.

when I go to page 2 the link looks like this
it display it BUT it display the wrong list of data.
it uses the 2 above in the link as offset...
so instead of 11-20 it display 3-12

in page 3 (base_url/controller/method/3)
is display 4-13. it uses the 3 as offset

this is the code.
// Controller
$limit = 10;
$data['categories'] = $this->model->get_all_categories($this->limit);
$config['base_url'] = site_url('admin/category_list');
$config['total_rows'] = $this->model->count_categories();
$config['per_page'] = $this->limit;
$config['uri_segment'] = 3;
$config['num_links'] = 2;
$config['use_page_numbers'] = TRUE;

public function get_all_categories($limit = 10) {
     return $this->db->limit($limit, $this->uri->segment(3))->get($this->tbl_categories)->result_object();

public function count_categories() {
     return $this->db->count_all_results($this->tbl_categories);

AND OH if I set $config['use_page_numbers'] = FALSE it works properly cause the link above is
base_url/method/     Page 1
base_url/method/10 Page 2
base_url/method/20 Page 3

so it uses the URI Segment properly. but I wanted to use page numbers I can't seem to fix it..
if anyone can help that would be great for the mean time I'll set the value to FALSE


public function example() {
    //For Pagination
        $uri = $this->uri->segment(3);
        if ($uri === false || $uri === null) {
            $uri = 0;
        //End Pagination
        if ($this->session->userdata('logged_in')) {
            //For Pagination
            $config['base_url'] = $this->config->base_url() . '/brand/managebrand';
            $config['total_rows'] = $this->db->count_all_results('brand');
            $config['per_page'] = 10;
            $data['pagination'] = $this->pagination->create_links();
            //End Pagination
            $session_data = $this->session->userdata('logged_in');
            $data['name'] = $session_data['name'];
            $data['brand'] = $this->brandmodel->brandlist($uri, $config['per_page']);
            $this->load->view('admin/managebrand', $data);

function brandlist($start = 0, $uri) {
        $this->db->order_by('brand_id', 'desc');
        $query = $this->db->query("SELECT * FROM `brand` LIMIT $start, $uri");
        return $query->result_array(); // returing array of data
<div class="pagenation"><?php echo $pagination; ?></div>
Web Developer

Theme © iAndrew 2016 - Forum software by © MyBB