select('service,supplier_id') ->group_by('service,supplier_id'); foreach ($t->find_all() as $group) { $zerorow = FALSE; foreach (ORM::factory('Service_Plugin_Adsl_Traffic')->where('service','=',$group->service)->where('supplier_id','=',$group->supplier_id)->order_by('date')->order_by('time')->find_all() as $spato) if ($spato->total() === 0) { if ($zerorow) { // Cant use delete(), as our primary key is not used in this table. $db = DB::query(Database::DELETE,DB::delete($spato->table_name()) ->where('service','=',$group->service) ->where('supplier_id','=',$group->supplier_id) ->where('date','=',$spato->date) ->where('time','=',$spato->time)); $db->execute(); } $zerorow = TRUE; } else $zerorow = FALSE; // An attempt to free some memory. $spato = NULL; } } } ?>