I am using pagination with codeigniter but everytime i get only one result added when i change page.
Let's be clear, in page 1
i have 15 different results, when i go to page 2
i get the same results with additional new result at the end, when i go to page 3
i get the same results as page 2
but with additional one new result at the end ect...
My code (Controller):
$limit = (is_numeric($this->uri->segment(3)))?($this->uri->segment(3) - 1):0;
$offset = 15;
$query = "SELECT * FROM results ";
$query .= " WHERE user_id = '" . @$grow['user']->user_id . "' AND state = 1 ";
$query .= " ORDER BY created_date DESC ";
$grow['results_count'] = $this->db->query($query)->result();
$query .= " LIMIT " . $limit . "," . $offset;
$grow['results'] = $this->db->query($query)->result();
$this->load->library('pagination');
$config['base_url'] = base_url() . "users/get";
$config['total_rows'] = count($grow['results_count']);
$config['per_page'] = 15;
$config['uri_segment'] = 3;
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><span>';
$config['cur_tag_close'] = '</span></li>';
$config['use_page_numbers'] = TRUE;
$this->pagination->initialize($config);
$grow['links'] = $this->pagination->create_links();
$grow['site'] = $this;
$this->view('users/get', $grow);
My view:
<?php
if (count($results) > 0) {
?>
<?php
foreach ($results as $row) {
?>
show results here
<?php
}
?>
<p><?php echo $links; ?></p>
<?php } else { ?>
No Result Found
<?php
}
?>
refer this link you will get better idea..
https://www.formget.com/pagination-in-codeigniter/
don't use custom query implement query like this
$this->db->limit($limit);
$this->db->where('id', $id);
$query = $this->db->get("contact_info");
Let me know if you have any issue.