where('client_id', $id) ->where('user_id', $user_id) ->where('level', $level) ->countAllResults(); return ($query > 0) ? true : false; } public function getAllClientRM() { return $this->db->table('client_rm') ->select('client_rm.client_id, client_rm.level,') ->select('user_profiles.first_name as account_manager') ->join('user_profiles', 'user_profiles.id = client_rm.user_id') ->where('level', 3) ->get() ->getResult(); } public function findAccountManagerEmail($client_id) { $builder = $this->db->table('client_rm'); $builder->select('user_profiles.email'); $builder->join('user_profiles', 'user_profiles.id = client_rm.user_id'); $builder->where('client_rm.client_id', $client_id); $builder->where('client_rm.level', 3); // Assuming level 3 is for account managers $result = $builder->get()->getResultArray(); if (count($result) > 0) { // Extract just the email values into a simple string array return array_column($result, 'email'); } else { return null; // or [] } } }