Race Results

Recent Club Races

“);
print(“

\n”);
print(”

\n”); print(”

\n”);
print(”

\n”);
print(”

\n”);
print(”

\n”);
print(”

\n”); $odd = 1;

var_dump($result);

while ($race = mysql_fetch_array($result)) {
if( $odd ) {
$odd = 0;
$class = “resultrowodd”;
} else {
$odd = 1;
$class = “resultroweven”;
}

print(‘

‘);
print(“\n”);
$RaceDate = sprintf(‘%s‘,
$race[“raceid”],
$race[“date”] );

print(“

\n”);

$RaceName = sprintf(‘%s%s %s‘,
$race[“raceid”],
$race[“name”],
$race[“description”]
? ‘,’
: ”,
$race[“description”] );

print(“

\n”);
print(“

\n”);
print(“

\n”);
print(“

\n”);
}
print(“

Date Course Dist Type
” . $RaceDate . “ ” . $RaceName . “ ” . $race[“dist”] . ‘ ‘ . $dist_unit . “ ” . $race[“tag”] . “

\n”);
} else if($_GET[‘mode’] == ‘race’ ) {

if (isset($_GET[‘raceid’]))
{
$raceid = sprintf(‘%d’,$_GET[‘raceid’]);
}
else
{
$raceid = 0;
}
// print(“

” . getRaceDesc( $raceid, $dist_unit ) . “

“);

$raceQuery = “SELECT course.dist, course.map, race.conditions ” .
” FROM race, course ” .
” WHERE race.courseid = course.courseid ” .
” AND race.raceid = ” . $raceid;

$result = mysql_query(“$raceQuery”);
if( $row = mysql_fetch_array($result)) {
$courseDist = $row[“dist”];
$conditions = $row[“conditions”];
$map = $row[“map”];

if( $map )
{
print(“

Profile/Map

“);
}

if( $conditions )
{
print( ‘‘);
}

} else {
//Error(‘Unknown raceID ‘ . $raceid);
}

//
// SHOW SELECTED RACE’S RESULTS
// (SORT BY DNF TO PUT ALL NON-FINISHERS LAST.)
//
$listquery = “SELECT result.time, ” .
” HOUR(result.time), ” . // [1]
” MINUTE(result.time), ” . // [2]
” SECOND(result.time), ” . // [3]
” rider.id, rider.gender, ” .
” rider.first, rider.last, ” .
” result.dnf, ” .
” race.courseid ” .
” FROM race, result, rider ” .
” WHERE race.raceid = result.raceid ” .
” AND result.riderid = rider.id” .
” AND race.raceid = $raceid ” .
” ORDER BY result.dnf, result.time ASC “;

$result = mysql_query($listquery);

print(“

\n”);
print(”

\n”);
print(”

\n”);
print(”

\n”);
print(”

\n”);
print(”

\n”);

print(”

\n”);
print(”

\n”);
print(”

\n”);
print(”

\n”);

$posit = 1;
$positM = 1;
$positF = 1;
$odd = 1;
$delete = 0;
$some = 0;
while ($race = mysql_fetch_array($result))
{
$some++;

if( $odd )
{
$odd = 0;
$class = “resultrowodd”;
}
else
{
$odd = 1;
$class = “resultroweven”;
}

print(‘

‘);
print(“\n”);

//
// DON’T COUNT POSITION IF “DNF”
//
if( !$race[“dnf”] )
{
print(‘

\n”);
}
else
{
print(“

\n”);
}

$FullName = sprintf(‘%s‘,
trim($race[“first”]),
$race[“id”],
trim($race[“last”]). “, ” .
trim($race[“first”]) );

print(“

\n”);

print(‘

\n”);
if( !$race[“dnf”] )
{
if($race[“gender”] == “M”)
{
print(‘

\n”);
}
else
{
print(‘

\n”);
}

$TimeLink = sprintf(‘%s‘,
trim($race[“first”]),
$race[“id”],$race[“courseid”], $race[“time”] );

print(“

\n”);

$thisHour = $race[1];
$thisMin = $race[2];
$thisSec = $race[3];
$timeInSecs = (60*60*$thisHour + 60*$thisMin + $thisSec);

//
// CALC SPEED
//
if( $timeInSecs )
{
$speed = sprintf(“%.2f”, ($courseDist * 60*60)/$timeInSecs);
}
else
{
$speed = “???”;
}
print(“

\n”);

//
// CALCULATE DELTA
//
if( $posit > 2 )
{
$deltaSecs = $timeInSecs
– (60*60*$firstHour + 60*$firstMin + $firstSec);

$hh = intval( $deltaSecs/3600 );
$deltaSecs = ($deltaSecs- ($hh * 3600));
$mm = intval($deltaSecs / 60);
$ss = ($deltaSecs – ($mm * 60));

//
// UNLIKELY TO BE AN HOUR
//
if( $hh )
$delta = sprintf(“+%02d:%02d:%02d”, $hh, $mm, $ss );
else
$delta = sprintf(“+%02d:%02d”, $mm, $ss );

}
else
{
$delta =”;
$firstHour = $race[1];
$firstMin = $race[2];
$firstSec = $race[3];
}
print(“

\n”);
}
else
{
//
// DNF – no time, gender posit, speed or delta
//
print(“

\n”);
print(“

\n”);
print(“

\n”);
print(“

\n”);
}
print(“

\n”);

}
print(“

Place Name M/F Gender
Place
Time Speed
$dist_unit/h
At
‘ . $posit++ . “ ” . $FullName . “ ‘ . $race[“gender”] . “ ‘ . $positM++ . “ ‘ . $positF++ . “ ” . $TimeLink . “ ” . $speed . “ ” . $delta . “ DNF

\n”);

if(!$some)
{
print ‘

Results not yet entered. Try again later.

‘;
}

} else if ($_GET[‘mode’] == ‘listriders’ ) {
$where = ”;

//
// PREPARE A WHERE CLAUSE ADDITION
//

//
// FLAG – DO WE NEED TO TEST FOR First OR LAST NAME?
//
$bFirst = 0;
$bLast = 0;

if( isset($_GET[“riderid”]) && $_GET[“riderid”] ) {
$where = sprintf(‘ AND rider.id = %d’, $_GET[“riderid”]);

//
// FIRST AND LAST EFFECTIVELY SET.
//
$bFirst = 1;
$bLast = 1;
} else {
if( isset($_GET[“last”]) && $_GET[“last”] ) {
$bLast = 1;
$where = sprintf(‘ AND rider.last like “%s%%”‘, $_GET[“last”]);
}
if( isset($_GET[“first”]) && $_GET[“first”] ) {
$bFirst = 1;
$whereFirst = sprintf(‘ AND rider.first like “%s%%”‘, $_GET[“first”]);
$where = $where . $whereFirst;
}
}

if( isset($_GET[“year”]) && $_GET[“year”] && $_GET[“year”] != -1 ) {
$whereYear = sprintf(‘ AND YEAR(race.date) = %d’, $_GET[“year”]);
$where = $where . $whereYear;
}
if( isset($_GET[“month”]) && $_GET[“month”] && $_GET[“month”] != -1 ) {
$whereMonth = sprintf(‘ AND month(race.date) = %d’, $_GET[“month”]);
$where = $where . $whereMonth;
}

if( isset($_GET[“courseid”]) && $_GET[“courseid”] && $_GET[“courseid”] != -1 ) {
$whereCourse = sprintf(‘ AND race.courseid = %d’, $_GET[“courseid”]);
$where = $where . $whereCourse;
}

$orderAscDesc = “”;

if( isset($_GET[“sortField”]) && $_GET[“sortField”] ) {
if( isset($_GET[“sortDirection”]) && $_GET[“sortDirection”] ) {
if( $_GET[“sortDirection”] == “DESC” ) {
$orderAscDesc = “DESC”;
} else {
$orderAscDesc = “”;
}
}
$orderby = sprintf(‘ ORDER BY %s %s’, $_GET[“sortField”], $orderAscDesc );
} else {
$orderby = ” ORDER BY race.date DESC “;
}

if( !$bLast && !$bFirst ) {
print ‘

Must enter (partial) first or last name. ‘;
print ‘Try again

‘;
} else {
//
// SHOW SELECTED RACES
//
$listquery = “SELECT race.raceid, race.typeid, tag, race.date, ” .
” location.name, course.dist, course.description, ” .
” result.time, result.dnf, ” .
” rider.first, rider.last “.
” FROM race, sysracetype, course, location, ” .
” result, rider ” .
” WHERE race.courseid = course.courseid ” .
” AND race.typeid = sysracetype.typeid ” .
” AND course.locid = location.locid ” .
” AND race.raceid = result.raceid” .
” AND result.riderid = rider.id” .
$where .
$orderby;

$result = mysql_query($listquery);

print(“

\n”);
print(”

\n”);

$params = PrepareLinkParams(‘date’, $orderAscDesc);

$SortDateLink = sprintf(‘Date‘,
$params );

print(”

\n”);
print(”

\n”);
print(”

\n”);
print(”

\n”);
print(”

\n”);

$params = PrepareLinkParams(‘time’, $orderAscDesc);
$SortTimeLink = sprintf(‘Time‘,
$params );

print(”

\n”);
print(”

\n”);

$some = 0;
$odd = 1;

while ($race = mysql_fetch_array($result)) {
$some++;

if( $odd ) {
$odd = 0;
$class = “resultrowodd”;
} else {
$odd = 1;
$class = “resultroweven”;
}

print(‘

‘);

print(“\n”);

$RaceDate = sprintf(‘%s‘,
$race[“raceid”],
$race[“date”] );

print(“

\n”);

$RaceName = sprintf(‘%s%s %s‘,
$race[“raceid”],
$race[“name”],
$race[“description”]
? ‘,’
: ”,
$race[“description”] );

print(“

\n”);

print(“

\n”);
print(“

\n”);

$FullName = trim($race[“last”]). “, ” . trim($race[“first”]);

print(“

\n”);
$sTime = $race[“dnf”] == 1 ? “DNF” : $race[“time”];
print(“

\n”);

print(“

\n”);

}
print(“

$SortDateLink Course Dist Type Name $SortTimeLink
” . $RaceDate . “ ” . $RaceName . “ ” . $race[“dist”] . ‘ ‘ . $dist_unit . “ ” . $race[“tag”] . “ ” . $FullName . “ ” . $sTime . “

\n”);

if(!$some) {
print ‘

No matching results were found.

‘;
}
}
}

function PrepareLinkParams($FieldToSort, $orderAscDesc)
{
//
// LINK HAS ALL ORIGINAL PARAMS.
// BUT SORT ORDER REVERSED (IF IT WAS THERE)
// AND SORT COLUMN SET TO USER CHOSEN COLUMN
//
$params = ”;
foreach( $_GET as $key => $value)
{
if( $key != ‘sortField’ && $key != ‘sortDirection’ )
$params = $params . “$key=$value” . ‘&’;
}

$params = $params . “sortField=$FieldToSort” . ‘&’;

if( $orderAscDesc == “DESC” )
{
$orderAscDesc = “”;
}
else
{
$orderAscDesc = “DESC”;
}

$params = $params . “sortDirection=$orderAscDesc”;
return $params;
}

?>