Codeigniter使用分页在每个页面上显示相同的数据。我认为URL
格式存在问题,因为它无法从 url 获取第3个uri 段。
我使用的代码是...
public function index()
{
$query = $this->db->query('SELECT * FROM categories');
$pagination_limit = '10';
$config = array();
$config['base_url'] = base_url().'business_list/';
$config['display_pages'] = true;
$config['first_link'] = 'First';
$config['total_rows'] = $query->num_rows();
$config['per_page'] = $pagination_limit;
$config['uri_segment'] = 3;
$config['full_tag_open'] = "<ul class='pagination pagination-right margin-none'>";
$config['full_tag_close'] = '</ul>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
$config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
$config['next_tag_open'] = '<li>';
$config['next_tagl_close'] = '</li>';
$config['prev_tag_open'] = '<li>';
$config['prev_tagl_close'] = '</li>';
$config['first_tag_open'] = '<li>';
$config['first_tagl_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tagl_close'] = '</li>';
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data['results'] = $this->Business_model->fetch_comments_data($config['per_page'], $page);
$data['links'] = $this->pagination->create_links();
$data['title'] = "Business List";
$this->load->view('categories',$data);
}
请帮助。
答案 0 :(得分:0)
花点时间了解你在那做什么。
$query = $this->db->query('SELECT * FROM categories');
您似乎未定义 LIMIT 和 OFFSET 。
我为您找到了一个有关pagination with codeigniter的很好的例子。
答案 1 :(得分:0)
您需要更改此内容:
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
收件人
$page = ($this->input->get('p') ? $this->input->get('p') : 0);
我认为 Codeigniter URI段在您的情况下不起作用,因为如果您的网址是这样的
http://127.0.0.1/hmvc/business_list/page/2
然后第一段为business_list
,第二段为page
,但是您使用查询字符串,因此需要进行更改