我有一个分页的博客。除了重复显示的项目外,一切正常。 这些项目在其他页面上随机重复显示。例如,在第二页上,它显示已在第一页上的项目。
所以,我在我的控制器中有这个功能。
public function index() {
//Pagination
$config['per_page'] = 4;
$config['num_links'] = 2;
$config['base_url'] = base_url().'blog/index';
$config['use_page_numbers'] = TRUE;
$num_rows = $this->db->get('posts');
foreach ($num_rows->result() as $row) {}
$num_rows = $num_rows->num_rows();
$num_rows = $num_rows;
$config['total_rows'] = $num_rows;
//Primeira página
$config['first_link'] = '<span style="font-weight: bold;color: rgb(225,2,38);"><<</span>';
//Última página
$config['last_link'] = '<span style="font-weight: bold;color: rgb(225,2,38);">>></span>';
//Página anterior
$config['prev_link'] = '<button type="select" class="selectarrowleft" href="#"><i class="fa fa-angle-left" aria-hidden="true"></i></button>';
//Próxima página
$config['next_link'] = '<button type="select" class="selectarrowright" href="#"><i class="fa fa-angle-right" aria-hidden="true"></i></button>';
//Páginas disponiveis
$config['num_tag_open'] = '<div>';
$config['num_tag_close'] = '</div>';
//Página corrente
$config['cur_tag_open'] = '<div id="current">';
$config['cur_tag_close'] = '</div>';
$this->pagination->initialize($config);
$this->db->order_by('id', 'DESC');
$data['blog'] = $this->db->get('posts', $config['per_page'], $this->uri->segment(4));
$this->load->view('frontend/template/header');
$this->load->view('frontend/template/nav_bar');
$this->load->view('frontend/pages/blog', $data);
$this->load->view('frontend/template/footer');
}
这是视图上的代码:
<?php
foreach ($blog->result() as $row) {
// The code for showing my blog articles
}
// pagination links
echo $this->pagination->create_links();
?>
如果我将此设为假:
$config['use_page_numbers'] = FALSE;
博客文章正确显示,无需重复文章。但我真的想拥有正确的页码。我能做什么?我见过这么多类似的问题,但我无法解决。