
<?

  $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";
  }

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

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

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

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

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

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

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

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

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

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


