Raceresults

query(“SELECT id, name, link, eventtype FROM event ORDER BY Enddate DESC”);
if ($raceQuery->num_rows > 0)
{
while($raceInfo = $raceQuery->fetch_assoc())
{
if($raceInfo[“eventtype”] == 1 || $raceInfo[“eventtype”] == 2)
printEachRace($dbConnection, $raceInfo);
}
}
else
{
//echo “

\n”;
echo “

Keine Ergebnisse

\n”;
}
}

function printEachRace($dbConnection, $raceInfo)
{
printRaceHeadder($raceInfo[“id”], $raceInfo[“name”], $raceInfo[“link”]);

$currentRaceQuery = getOrderedRaceResults($raceInfo[“id”], $dbConnection);

if ($currentRaceQuery->num_rows > 0)
{
printCurrentRaceResultAsTable($currentRaceQuery, $dbConnection);
}
else
{
echo “

\n”;
echo “

Keine Ergebnisse

\n”;
}
echo “
\n”;
}

function printRaceHeadder($raceID, $raceName, $raceLink)
{
echo “

\n”;
echo “Race: $raceName

\n”;
}

function getOrderedRaceResults($event_id, $dbConnection)
{
return $dbConnection->query(“SELECT id, teamname, teilnehmer1_ID, teilnehmer2_ID, result, finisher
FROM result
where event_id = “.$event_id.”
order by finisher desc, comment, result”
);
}

function printCurrentRaceResultAsTable($currentRaceQuery, $dbConnection)
{
printCurrentRaceHeadder();
$rank = 1;
while($currentTeam = $currentRaceQuery->fetch_assoc())
{
getSingleTeamResultAndPrintResult($currentTeam, $rank, $dbConnection);
$rank++;
}
echo “

\n”;
}

function printCurrentRaceHeadder()
{
echo “

\n”;
echo “

\n”;
}

function getSingleTeamResultAndPrintResult($currentTeam, $rank, $dbConnection)
{
$rank = ($currentTeam[“finisher”] == ‘0’)? ‘…’ : $rank;
$teamname = $currentTeam[“teamname”];
$teilnehmer1Link = “href=’teilnehmer/?userID=”.$currentTeam[“teilnehmer1_ID”].”‘”;
$teilnehmer2Link = “href=’teilnehmer/?userID=”.$currentTeam[“teilnehmer2_ID”].”‘”;
$participent1 = findNameOfParticipent($currentTeam[“teilnehmer1_ID”], $dbConnection);
$participent2 = findNameOfParticipent($currentTeam[“teilnehmer2_ID”], $dbConnection);

$finish = $currentTeam[“result”];
if ($currentTeam[“finisher”] == ‘0’)
echo “

\n”;
$finish = ($finish == ‘0000-00-00 00:00:00’)? ‘…’ : $finish;
echo “

\n”;
}

function findNameOfParticipent($participentID, $dbConnection)
{
$selectName = “SELECT name FROM teilnehmer where id = $participentID”;
$nameresult = $dbConnection->query($selectName);
if ($nameresult->num_rows > 0)
{
$selectname = $nameresult->fetch_assoc();
return $selectname[“name”];
}
else
{
return “…”;
}
}

?>



\n”;
echo “

Platz Teamname Teammembers Finishing time
Disqualifiziert:
$rank. $teamname $participent1 & $participent2 $finish
createDbConnection();

printRaceResults($dbConnection);
$dbConnection->close();

?>