[英]pagination issue using codeigniter
I am using pagination with codeigniter but everytime i get only one result added when i change page. 我正在使用codeigniter进行分页,但是每次更改页面时,每次添加的结果只有一次。
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... 让我们清楚一点,在
page 1
我有15个不同的结果,当我转到page 2
我得到相同的结果,最后还有其他新结果,当我转到page 3
我得到与page 2
相同的结果,但还有另外一个最后的新结果等...
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/ 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. 如果您有任何问题,请告诉我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.