<?php
	include_once("db.php");

	//make result object
	$result = array();
	$result['ok'] = false;

	//get post data
	$postdata = file_get_contents("php://input");
	$post = json_decode($postdata, true);

	if(isset($post['idrace'])) {
		//fetch the measurements
		$measurementsfetch = pg_prepare($dbconn, "measurementsfetch", "select * from measurement where idrace = $1");
		$measurementsfetch = pg_execute($dbconn, "measurementsfetch", array($post['idrace']));

	} else {
		//do nothing yet...
	}



	//build result object
	$measurements = array();
	while($row = pg_fetch_assoc($measurementsfetch)) {
		$measurements[] = $row;
	}

	$result['measurements'] = $measurements;

	//return data
	$result['ok'] = true;

	//print message
	$resultjson =  json_encode($result);

	echo $resultjson;
?>
