$this->db->group_start(); $this->db->where('contracts_id_client_purchaser', $id_client); $this->db->or_where('contracts_id_client_supplier', $id_client); $this->db->group_end(); $this->db->where('contracts_active', 1); $this->db->order_by('id_contracts', 'desc'); $query = $this->db->get('contracts');