使用codeigniter的分页问题

时间:2016-10-12 13:43:52

标签: php codeigniter pagination

我正在使用codeigniter分页,但每当我更改页面时,我只会添加一个结果。

让我们清楚一点,在page 1我有15个不同的结果,当我去page 2时,我会在最后获得相同的结果并获得额外的新结果,当我去{ {1}}我得到与page 3相同的结果,但最后还有一个新结果...

我的代码(控制器):

page 2

我的观点:

$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);

1 个答案:

答案 0 :(得分:0)

参考此链接,您将获得更好的想法..

https://www.formget.com/pagination-in-codeigniter/

不要像这样使用自定义查询工具查询

 $this->db->limit($limit);
    $this->db->where('id', $id);
    $query = $this->db->get("contact_info");

如果您有任何问题,请告诉我。