I seem to be having an issue with the pagination in codeigniter and my search query.
Code
public function index($page = 0){
$this->db->select('a.UserID, a.Username, a.UserFullName, a.UserJoined,
(Select Top 1 p.phoneNumber From vwSelectUserPhone p Where p.userID = a.userID) As PhoneNumber,
(Select Top 1 e1.emailAddress From vwSelectUserEmail e1 Where e1.userID = a.userID) As EmailAddress,
(Select Top 1 c1.shipCompany From vwSelectOrderAddresses c1 Where c1.userID = a.userID) As UserCompany');
//$this->db->order_by('UserJoined', 'DESC')
$this->db->distinct();
if($_POST){
$usid = $this->input->post('UserID');
$ustxt = $this->input->post('TextSearch');
if(!empty($ustxt) || !empty($usid)){
if(!empty($usid)){
$this->db->where('a.UserID', $usid);
}elseif(!empty($ustxt)){
$this->session->set_userdata('USrch_Txt', $ustxt);
$this->db->join('vwSelectUserAddress b', 'b.userID = a.userID', 'left');
$this->db->join('vwSelectUserEmail c', 'c.userID = a.userID', 'left');
$this->db->join('vwSelectUserPhone d', 'd.userID = a.userID', 'left');
$this->db->join('vwSelectUserNotes e', 'e.userID = a.userID', 'left');
$this->db->join('vwSelectUserVehicle f', 'f.userID = a.userID', 'left');
$this->db->like('a.Username', $ustxt);
$orlike = array('a.UserFullName'=>$ustxt,
'b.addressStreet1'=>$ustxt,
'b.addressStreet2'=>$ustxt,
'b.addressCity'=>$ustxt,
'b.addressState'=>$ustxt,
'b.addressPostalCode'=>$ustxt,
'c.emailAddress'=>$ustxt,
'd.phoneNumber'=>$ustxt,
'e.Note'=>$ustxt,
'f.vehMake'=>$ustxt,
'f.vehModel'=>$ustxt,
'f.vehYear'=>$ustxt,
'f.vehTran'=>$ustxt,
'f.vehMake'=>$ustxt,
'f.vehEngine'=>$ustxt,
'f.vehDescription'=>$ustxt,);
$this->db->or_like($orlike);
}
}
}
$this->db->order_by('a.UserFullName', 'asc');
$this->db->limit(12, $page);
$qry = $this->db->get('vwSelectUser a');
$rs = $qry->result_array();
$config['base_url'] = '/users';
$config['per_page'] = 12;
$config['total_rows'] = $this->db->count_all('vwSelectUser');
$config['num_links'] = 5;
$config['first_link'] = '<span class="fa fa-angle-double-left page_num"></span>';
$config['last_link'] = '<span class="fa fa-angle-double-right page_num"></span>';
$config['cur_tag_open'] = '<span class="page_num bold">';
$config['cur_tag_close'] = '</span>';
$config['next_link'] = '<span class="fa fa-angle-right page_num"></span>';
$config['prev_link'] = '<span class="fa fa-angle-left page_num"></span>';
$config['uri_segment'] = 2;
$config['num_tag_open'] = '<span class="page_num">';
$config['num_tag_close'] = '</span>';
$this->pagination->initialize($config);
$data['rs'] = $rs;
$data['paging'] = $this->pagination->create_links();
$data['current_page'] = $page;
$this->load->view('templates/header');
$this->load->view('pages/users/list', $data);
$this->load->view('templates/footer');
}
As you can see, I have some search parameters in here. I need to change the $config['total_rows']
to $this->db->count_all_results('vwSelectUser')
, however when I do I am faced with the following error:
Column "vwSelectUser.UserFullName" is invalid in the ORDER BY clause because it is not contained in either an aggregate function or the GROUP BY clause.
How can I fix this, #1 so it will display the proper pagination links (if there should be any), #2 to get the proper count of the filtered return?
I had though that by doing this: $config['total_rows'] = ($_POST) ? $this->db->count_all_results('vwSelectUser a') : $this->db->count_all('vwSelectUser a');
that it should do the trick, but I get the error specified.