$db->Execute($sql, $values);
     }
 }
 if (!empty($bracketdata['matches']) && is_array($bracketdata['matches'])) {
     $fields = array_keys($bracketdata['matches'][0]);
     $fixer = array_search('bracket_id', $fields);
     $fixer2 = array_search('match_id', $fields);
     if ($fixer !== FALSE && $fixer2 !== FALSE) {
         //TODO flag 'added'
         $fixer3 = array_search('nextm', $fields);
         //irrelevant for RR
         $fixer4 = array_search('nextlm', $fields);
         //ditto and for KO
         $mc = count($bracketdata['matches']);
         $sch = new tmtSchedule();
         $mid = $sch->ReserveMatches($db, $pref, $mc);
         $offset = $mid - $bracketdata['matches'][0]['match_id'];
         //lowest match-no. is sorted 1st
         foreach ($bracketdata['matches'] as $thisone) {
             $values = array_values($thisone);
             $values[$fixer] = $bid;
             $values[$fixer2] = $mid;
             if ($fixer3 !== FALSE) {
                 if ($values[$fixer3]) {
                     $values[$fixer3] += $offset;
                 }
             }
             if ($fixer4 !== FALSE) {
                 if ($values[$fixer4]) {
                     $values[$fixer4] += $offset;
                 }