每个帖子的用户选择页面分页


Pagination with User select page per post

我正在使用分页的编码点火器,但是当我选择每页的记录时,它显示数据但是当我单击下一页按钮时,默认情况下它将重定向到 3 页,我们每页有 25 个数据字段,因此它会按默认值划分页面上的数据。

这是控制器

        function search($page=0)
      {     
        // selecting per page data              
        if ($this->input->post('per_page')!='') {
                 $recordperpage = $this->input->post('per_page');
                 $per =  $this->input->post('per_page');
                 $page = $this->input->post('per_page');
                echo $this->session->userdata('per');
            } 

            else {
                $recordperpage = 25;    
            }
      $keyword = $this->input->post('keyword');
      $result['front'] = $this->search_model->search($keyword,$page,$recordperpage);
    $mypaing['total_rows']= $this->search_model->listing_num('*','tabel_name','flag',1,'keyword',$keyword);
    $mypaing['base_url']    =   base_url()."admin/h_search/search/";
    $mypaing['per_page']    =   $recordperpage;
    $mypaing['uri_segment'] =   4;      
    $this->pagination->initialize($mypaing);
    $result['recordperpage'] = $recordperpage;
    $result['paginglink']   =   $this->pagination->create_links();
    $data['page_heading']   = "Doctor Search Result";
   $data['contents'] = $this->load->view('admin/listing/search',$result,true);  
    $this->load->view('admin/template',$data);
    }`enter code here`
模型

用于从搜索中获取记录的模型

 function search($keyword,$page,$recordperpage)
{    
    $sql ="SELECT * FROM tabel_name WHERE flag = 1  AND keyword LIKE '%".$keyword."%' 
    LIMIT ".$page.",".$recordperpage."" ;
    $result=$this->db->query($sql);
    return $result; 
} 
function listing_num($select,$from,$where_colum,$where,$where_colum1,$where1)
{
    $this->db->select($select);
    $this->db->from($from);
    $this->db->where($where_colum,$where);
    $this->db->where($where_colum1,$where1);

    $query=$this->db->get();
    return $query->num_rows();
}

视图

     <div class="counter">
      <input type="hidden" value="<?=$recordperpage?>" name="rpp_hidden" id="rpp_hidden" />
    <select onchange="this.form.submit();" name="per_page" id="per_page">
    <option value="25" <? if ($recordperpage == 25) {  print 'selected=selected'; }?>  >25</option>
    <option value="50" <? if ($recordperpage == 50) {  print 'selected=selected'; }?> >50</option>
    <option value="75" <? if ($recordperpage == 75) {  print 'selected=selected'; }?> >75</option>
    <option value="100" <? if ($recordperpage == 100) {  print 'selected=selected'; }?> >100</option>
    </select> per page 
  </div>
</div>

当我选择每个帖子的数据时,它将重定向到第 1 页,如果我选择每页 50 的记录,则显示的数据从 0 到 50

提前致谢

如果不是搜索,您在哪里设置偏移量?尝试在 if 语句上方添加此内容。如果没有 uri 段 4,就像您第一次加载页面时一样,它会将您的偏移量设置为 0,如果有,它将使用该段。然后,如果是搜索,您的 if 语句将覆盖它:

        $page = ($this->uri->segment(4) ? $this->uri->segment(4) : 0);