har*_*ham 5 php mysql pagination codeigniter
我已经阅读了有关Stackoverflow的所有问题,并且没有看到问题的确切答案.我目前正在使用codeigniter分页库来使用限制和偏移量生成我的分页链接:
$config['base_url'] = base_url() . 'explore/featured/index/';
$config['total_rows'] = $this->Projects_model->get_featured_count();//Count featured projects
$config['per_page'] = 12;
$config['uri_segment'] = 4;
$config['display_pages'] = FALSE;
$config['next_link'] = 'Older →';
$config['prev_link'] = '← Newer';
$this->pagination->initialize($config);
$limit = $config['per_page'];
$offset = $this->uri->segment(4);
$data['pagination'] = $this->pagination->create_links();
$data['projects'] = $this->Projects_model->get_featured($limit, $offset); //get featured projects from database
Run Code Online (Sandbox Code Playgroud)
上面的代码限制了我的查询的输出值,并使用了我的第4个URI段中包含的偏移量.
如何将以下代码更改为页码??? 似乎是不可能的,因为我将不再能够在我的网址中使用偏移量.
$limit * $page_number上面提到的并没有返回一个真正的偏移作为起点,并在页码为1时产生问题,因为此时偏移量必须为0.这对我有用:
$offset = ($page_number == 1) ? 0 : ($page_number * $config['per_page']) - $config['per_page'];
Run Code Online (Sandbox Code Playgroud)