
<?

  $year = date("Y");
  $sql = "SELECT ID, NAME, LENGTH, CLIMB from RACES where YEAR like '".$year."'";
  $result = $conn->query($sql);
  if ($result->num_rows > 0){
    $table_registered = '';
    while($row = $result->fetch_assoc()) {
      $races[] = $row;
    }
  }
  foreach($races as $race){
    $race_blob[$race['ID']] = $race['NAME'];
  }

$sql = "SELECT ID, NICK, RACE, TIME FROM REGISTERED";
  $result = $conn->query($sql);
  if ($result->num_rows > 0){
    $reg_racers = [];
    while($row = $result->fetch_assoc()) {

      $reg_racers[$row["RACE"]][] = ["ID" => $row["ID"], "NICK" => $row["NICK"], "RACE" => $race_blob[$row["RACE"]], "TIME" => $row["TIME"]];
    }
  }else{
  echo "0 results";
  }
?>


