db ->select('ea_users.*') ->from('ea_users') ->join('ea_roles', 'ea_roles.id = ea_users.id_roles', 'inner') ->where('ea_roles.slug', 'provider'); $providers = $this->db->get()->result_array(); foreach($providers as &$provider) { $this->db ->select('id_services') ->from('ea_services_providers') ->where('id_users', $provider['id']); $providerServices = $this->db->get()->result_array(); if (!isset($provider['services'])) { $provider['services'] = array(); } foreach($providerServices as $providerService) { $provider['services'][] = $providerService['id_services']; } } return $providers; } } ?>