Reputation: 135
I have created pagination in my page it needs to load 4650 columns.it counts the value correctly then the limit is LIMIT_PER_PAGE.but it load whole columns in the first page then in the second page it loads first 50 then it loads first 100 then it loads first 100+50=150 like that my controller code is
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();
}
then my model page is
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'];
}
in my view page is i have to use under the table like this
<?php echo $data['pagination'];
Upvotes: 0
Views: 145
Reputation: 399
You have incorrect order of passing the argument for limit and offset
in getcustomerall function correct order of data passing.
$this->model_profile->getcustomerall($limit,$offset,$order_column,$order_type,$filter);
function getcustomerall($offset,$limit,$order_column,$order_type,$parameters)
Upvotes: 1