Welcome Guest, Not a member yet? Register   Sign In
Pagination only displays the first 10 records
#1

I am trying to paginate a Codeigniter 3 application without using the framework's pagination library. More exactly, I want to paginate a table with about 100 rows. For this purpose:
In the home controller I have:
Code:
public function index() {
   $this->load->model('Customer');
   $this->load->library('pagination');
   $config = [
       'base_url' => base_url("index.php"),
       'per_page' => 10,
       'total_rows' => $this->Customer->get_num_rows(),
       'uri_segment' => 3,
       'first_tag_open' =>  '<li>',
       'first_tag_close' => '</li>',
       'last_tag_open' =>  '<li>',
       'last_tag_close' => '</li>',
       'full_tag_open' =>  '<ul class="pagination">',
       'full_tag_close' => '</ul>',
       'next_tag_open' =>  '<li>',
       'next_tag_close' => '</li>',
       'prev_tag_open' =>  '<li>',
       'prev_tag_close' => '</li>',
       'num_tag_open' =>   '<li>',
       'num_tag_close' =>  '</li>',
       'cur_tag_open' =>   '<li class="active"><a>',
       'cur_tag_close' =>  '</a></li>',
   ];
   $this->pagination->initialize($config);
   $customers = $this->Customer->getCustomers($config['per_page'], $this->uri->segment($config['uri_segment']));
   $this->load->view('home', ['records'=>$customers]);
}

In the Model file I have:
Code:
class Customer extends CI_Model {
public function __construct() {
   $this->load->database();
}

public function getCustomers($limit, $offset) {
   $this->db->limit($limit, $offset);
   $query = $this->db->get('customers');
   return $query->result();
}
}

Finaly, the view:
Code:
<div class="pagination-container text-center">
   <?php echo $this->pagination->create_links(); ?>
</div>

The pagination is displayed and properly formatted; so are the first 10 records

[Image: 1Roe3.png]


But if I click on page 2, or any other page, I get the same first 10 records as can be seen in the image below:

[Image: 7lEzB.png]

The url of page 2 is:

Code:
http://localhost/cicrud/index.php?page=2


I did something wrong, I can't understand what. Any help? Thank you!
Reply
#2

I think the problem is in your base_url from pagination library.
test this.
Code:
 $config = [
       'base_url' => site_url(site_url(uri_string(2)),
        'uri_segment' => 3

I think that you wil have a problem with limit functionality later.
so when you call
Code:
$this->Customer->getCustomers($config['per_page'], $this->uri->segment($config['uri_segment']));
change it for :
Code:
$this->Customer->getCustomers($config['per_page'], $this->uri->segment($config['uri_segment'])*$config['per_page']);
Reply
#3

(08-17-2017, 12:05 AM)Ajax30 Wrote: I am trying to paginate a Codeigniter 3 application without using the framework's pagination library.
Is this correct? Everything indicates that you ARE using CI's pagination library...
Reply
#4

if you use $this->pagination->initialize($config), $this->pagination->create_links(), you are using codeigniter´s pagination library.

what´s the url of your first pagination page?
Also, the limit function first parameter should be per_page, and the second the number of row to start listing = (page-1)*per_page.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB