codeigniter中的分页按每页的限制递增

问题描述 投票:0回答:1

我在页面中创建了需要加载4650列的分页。正确计算值,然后限制为LIMIT_PER_PAGE。但是它在第一页中加载整列然后在第二页加载前50然后它先加载100然后它首先加载100 + 50 = 150就像我的控制器代码一样

function cprofile($offset =0,$order_column='id',$order_type ='desc')
{
    $filter = array();
    if(isset($_GET)){
         $filter['customer'] = (isset($_GET['customer']) && $_GET['customer']!=NULL) ? $_GET['customer'] : NULL;
          $filter['mobile'] = (isset($_GET['mobile']) && $_GET['mobile']!=NULL) ? $_GET['mobile'] : NULL;
           $filter['nearby'] = (isset($_GET['nearby']) && $_GET['nearby']!=NULL) ? $_GET['nearby'] : NULL; //for searching the fields.
    }
    else{
        $filter['customer'] = NULL;
        $filter['mobile'] = NULL;
        $filter['nearby'] = NULL;
    }
    $limit = ITEM_PER_PAGE;
    $data['result']=$this->model_profile->getcustomerall($limit,$offset,$order_column,$order_type,$filter);
    $data['counts']=$this->model_profile->getProfilecount($filter);

    $this -> load -> library('pagination');
    $config['base_url'] = site_url("admin/pcustomer/cprofile");
    $config['total_rows'] = $data['counts'];
    $config['uri_segment'] = 4;
    $config['per_page'] = $limit;
    $config['display_pages'] = TRUE;
    $config['full_tag_open'] = "<ul class='pagination'>";
    $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>";
    $config['suffix'] = '?' . http_build_query($_GET, '', "&");
    $config['first_url'] = $config['base_url'] .$config['suffix'];
    $this -> pagination -> initialize($config);
    $data['pagination'] = $this -> pagination -> create_links();

    $data['new_order'] = ($order_type == 'asc' ? 'desc' : 'asc');
    $data['offset'] = $offset;

    $data['customer'] = $filter['customer']; 
    $data['mobile'] = $filter['mobile'];
    $data['nearby'] = $filter['nearby'];//search fields

    $this->theme_lib->data=$data;
    $this->theme_lib->view ='profile/cprofile';
    $this->theme_lib->title = 'D2D | Customer Profile';
    $this->theme_lib->pageFoot= 'profile/cprofile_foot';
    $this->theme_lib->pageHead= 'profile/cprofile_head';
    $this->theme_lib->render();
}

然后我的模型页面是

 function getcustomerall($offset,$limit,$order_column,$order_type,$parameters)
{
    $this->db->select('c.*,s.name as streetname');
    if($parameters['customer']!=NULL){
       $this->db->where('c.id',$parameters['customer']);
    }
    if($parameters['mobile']!=NULL){
       $this->db->where('c.mobile',$parameters['mobile']);
    }
    if($parameters['nearby']!=NULL){
        $this->db->where('c.nearby',$parameters['nearby']);
    }

     if(!empty($order_column) || !empty($order_type)){
        $this->db->order_by($order_column,$order_type);
    }else{
        $this->db->order_by('c.id','asc');
    }
    if($limit!=0){
        $this->db->limit($limit,$offset);
    }
    $last=2;
    $this->db->where('c.lastAttendance',$last);
    $this->db->join('street s','c.streetid=s.id','left');
    $query = $this->db->get('customer c');
    if($query->num_rows()>0){
        return $query->result_array();
    }else{
        return FALSE;
    } 
}
function getProfilecount($parameters)
{
     $this->db->select('COUNT(*) as count');
    if($parameters['customer']!=NULL){
        $this->db->where('c.id',$parameters['customer']);
    }
    if($parameters['mobile']!=NULL){
        $this->db->where('c.mobile',$parameters['mobile']);
    }
    if($parameters['nearby']!=NULL){
        $this->db->where('c.nearby',$parameters['nearby']);
    }
    $last=2;
    $this->db->where('c.lastAttendance',$last);
    $this->db->join('street s','c.streetid=s.id','left');
    $query = $this->db->get('customer c');
    $result = $query->row_array();
    return $result['count'];
}

在我的视图页面是我必须在这样的表下使用

 <?php echo $data['pagination'];
php codeigniter-3
1个回答
1
投票

传递限制和偏移量的参数的顺序不正确

在getcustomerall函数中正确的数据传递顺序。

$this->model_profile->getcustomerall($limit,$offset,$order_column,$order_type,$filter);

function getcustomerall($offset,$limit,$order_column,$order_type,$parameters)
© www.soinside.com 2019 - 2024. All rights reserved.