1
public function index($page = 0) {
    $this->load->library('pagination');
    $conf = array(
        'total_rows' => 11,
        'base_url' => 'localhost/admin/product/index',
        'per_page' => 10,
        'use_page_numbers' => false
    );
    $this->pagination->initialize($conf);
    $this->load->view('product/index');
}

In view

<?php echo $this->pagination->create_links(); ?>

In the first page it work correctly. When I click on the page 2 link, it only display ONE product, this was correct, but the pagination links for current page still in page ONE. Suppose this should be page TWO.

which part I did wrong?

Js Lim
  • 3,625
  • 6
  • 42
  • 80

1 Answers1

0

Well, the pagination class uses "per_page" in the query string. So, you have to divide that number by 10 (in your case) and add 1 to get the real page number, i.e.:

localhost/product/index (page 1)
localhost/product/index?per_page=10 (page 2)
localhost/product/index?per_page=20 (page 3)
...
localhost/product/index?per_page={10n) (page n+1)

This is useful to use directly in the database limit clause:

$this->db->limit(10, $this->input->get('per_page'))...

I think that's why CI chose to do it that way....

landons
  • 9,502
  • 3
  • 33
  • 46
  • CI_Pagination Object ( [base_url] => http://localhost/project/admin/product/index [prefix] => [suffix] => [total_rows] => 11 [per_page] => 10 [num_links] => 2 ... } This is the configuration of Pagination object. I still cannot find out the problem. – Js Lim Dec 03 '11 at 09:10
  • I had found the problem, the answer I had commented above. Thanks for your answer anyway. – Js Lim Dec 03 '11 at 10:03
  • That's frustrating. Didn't realize you were using segments and not query strings. Oh well. Upvote for the effort? ;) – landons Dec 03 '11 at 10:24