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

时间:2013-01-31 12:31:54

标签: php codeigniter jquery-plugins pagination

我正在使用使用分页的codeigniter,但是当我选择每页的记录时,它会显示 数据,但当我点击下一页按钮时,它将重定向到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>

                       

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

提前致谢

1 个答案:

答案 0 :(得分:0)

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

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