Welcome Guest, Not a member yet? Register   Sign In
Active Record LIKE on join query
#3

Thanks for that, mwhitney. I figured it out after I'd posed the question. The trick, as you have done in your sample code is to pass an empty string to the count_all_results function. I couldn't respond immediately as I needed the nod from the moderator before I could edit again.

To anyone else: set up your like and or_like statements. Set up your from and join statements. Use count_all_results with no parameters.

Code:
$temp = $this->input->post('text', TRUE);
if($temp > ''){
$this->db->like('tbl_users.usr_Lastname',  $temp, 'both');
$this->db->or_like('tbl_groups.grp_Area', $temp, 'both');
$this->db->or_like('tbl_systems.sys_Location', $temp, 'both');
etc., etc.,
}

// Record count
$this->db->from('tbl_users')
->join('tbl_groupmembers', 'tbl_groupmembers.gm_UserID = tbl_users.usr_UserID', 'inner')
->join('tbl_groups', 'tbl_groups.grp_ID = tbl_groupmembers.gm_GroupID', 'inner')
->join('tbl_rights', 'tbl_rights.r_GroupID = tbl_groups.grp_ID', 'inner')
->join('tbl_systems', 'tbl_systems.sys_ID = tbl_rights.r_SystemID', 'inner');
$jTableResult['TotalRecordCount'] = $this->db->count_all_results(''); // <---- Pass empty string to function.
Reply


Messages In This Thread
Active Record LIKE on join query - by Transistor - 02-15-2015, 01:09 PM
RE: Active Record LIKE on join query - by Transistor - 02-17-2015, 03:22 PM



Theme © iAndrew 2016 - Forum software by © MyBB