Reputation: 6656
Base on the title above, I have a pagination in codeigniter and it displays exactly what I wanted on the first page. But when I click on the 2nd page it displays the same as the first page. Any help will be appreciated.
Model:
public function get_users ($limit, $start) {
$this->db->limit($limit, $start);
$query = $this->db->get ('auth_users');
$result = $query->result ();
foreach ($result as $key => $value) {
$data[$key] = array(
'id' => $value->id,
'firstname' => $value->first_name,
'lastname' => $value->last_name,
'datereg' => $value->date_registered,
'email' => $value->email,
'status' => $value->status ? 'Active' : 'Inactive'
);
}
return $data;
}
Controller:
public function users_page () {
// Pagination
$config['base_url'] = site_url('main/index');
$config['total_rows'] = $this->db->count_all('auth_users');
$config['per_page'] = 5;
$config['uri_segment'] = 3;
$choice = $config["total_rows"] / $config["per_page"];
$config["num_links"] = round($choice);
// Config pagination for bootstrap
$config['full_tag_open'] = '<ul class="pagination pagination-sm">';
$config['full_tag_close'] = '</ul>';
$config['first_link'] = false;
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['last_link'] = false;
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['next_link'] = '»';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['prev_link'] = '«';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data['users'] = $this->user->get_users($config["per_page"], $page);
$data['pagination'] = $this->pagination->create_links();
// $data['users'] = $this->user->get_users();
$data['title'] = 'Exer-Claide | Members area';
$this->load->view('fragments/header', $data);
$this->load->view('fragments/footer');
$this->load->view ('user_page' , $data);
}
Upvotes: 0
Views: 64
Reputation: 175
Check the value of $this->uri->segment(3)
. For example
echo $this->uri->segment(3);
It is likely that this will not give the appropriate value. If correct , whenever swiped page should give you another value.
Example:
$this->uri->segment(3) = 1
Next page
$this->uri->segment(3) = 2
If not give you different values, change the value.
Example:
$this->uri->segment(3) or $this->uri->segment(2)
The function $this->uri->segment() return the value of url in determinate position.
Upvotes: 0
Reputation: 11987
Try this
replace
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
to
$p = isset($_GET['page']) ? $_GET['page'] : 0;
$page = ($p) ? $p : 0;
Upvotes: 1