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


Messages In This Thread
Pagination only displays the first 10 records - by Ajax30 - 08-17-2017, 12:05 AM



Theme © iAndrew 2016 - Forum software by © MyBB