vm1.cleaneduptime and vm3.idrace = vm1.idrace) where vm1.idrace = $1 order by vm1.idrace, laptime"); $result['lasterror'].=pg_last_error()."\n"; $teamfetch = pg_execute($dbconn, "teamfetch", array($tier, $poule, $idchampionship)); $result['lasterror'].=pg_last_error()."\n"; //resulting teams array $teams = array(); while($row = pg_fetch_assoc($teamfetch)) { $team = $row; $team['races'] = array(); $idteam = $row['idteam']; $result['debugracefetch'] = $tier.' '.$poule.' '.$idchampionship.' '.$idteam; //loop over each race $racefetchexec = pg_execute($dbconn, "racefetch", array($tier, $poule, $idchampionship, $idteam)); $result['lasterror'].=pg_last_error()."\n"; while($racerow = pg_fetch_assoc($racefetchexec)) { $result['GETTING IN IT'] = true; $race = array(); $race['idrace'] = $racerow['idrace']; $race['laptimes'] = array(); //fetch the laptimes $laptimefetch = pg_execute($dbconn, "laptimefetch", array($race['idrace'])); $result['lasterror'].=pg_last_error()."\n"; while($laptimerow = pg_fetch_assoc($laptimefetch)) { $laptime = array(); $laptime['laptime'] = $laptimerow['laptime']; $race['laptimes'][] = $laptime; } $team['races'][] = $race; } $teams[] = $team; } $result['teams'] = $teams; $result['ok'] = true; //print message $resultjson = json_encode($result); echo $resultjson; ?>