function displayPastMaze($mapType, $name, $daysago = 1) {
//Ensure no cheating
if ($daysago < 1)
return;
$sql = "SELECT
maps.ID as mapID,
solution,
users.displayName as Name,
SUM(solutions.moves) as Moves,
timediff(solutions.dateModified, maps.dateCreated) as Timetaken
FROM `maps`
JOIN `solutions`
ON maps.ID = solutions.mapID
JOIN `users`
ON solutions.userID = users.ID
JOIN `mapOfTheDay`
ON maps.ID = mapOfTheDay.mapID
WHERE DATE_ADD(CURDATE(), INTERVAL -$daysago DAY) =
DATE_FORMAT(solutions.dateModified,'%Y-%m-%d')
AND DATE_ADD(CURDATE(), INTERVAL -$daysago DAY) =
DATE_FORMAT(maps.dateCreated,'%Y-%m-%d')
AND `mapType` = '$mapType'
GROUP BY solutions.userID
ORDER BY Moves DESC, `dateModified` ASC
";
$result = mysql_query($sql);
$statname = "Yesterday's Best $name:";
if ($daysago > 1) {
$statname = "$daysago days ago's Best $name:";
}
$stats = displayStats($result, $statname);
$pastMap = pastMap($mapType, $daysago);
$mapID = $pastMap;
$mapcode = getMapCode($mapID);
$map = GenerateMapByCode($mapcode);
$sql = "SELECT `moves`, `displayName`, `solution`
FROM `solutions`, `users`
WHERE `mapID` = '$mapID' AND
`userID` = users.ID
ORDER BY `moves` DESC, `dateModified` ASC
LIMIT 1";
$result = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($result) > 0) {
list($bestMoves, $byName, $solution) = mysql_fetch_row($result);
//echo "Best solution for this map: $bestMoves by $byName";
//$map = MergeMapSolution($map, $solution);
//echo DisplayMap($map, $mapID);
}
echo '
';
echo "
";
echo '
';
echo $stats;
echo '
';
echo '
';
echo "Best solution for this map: $bestMoves by $byName ";
echo DisplayMap($map, $mapID, 'example', 2);
echo '
';
echo '
';
}
function displaystats($result, $caption = NULL) {
//Get names.
$headers .= "
Rank | ";
$headers .= "
Name | ";
$headers .= "
Moves | ";
$headers .= "
Time taken | ";
//Start table
$r .= "
";
$r .= "$caption";
//Headers on the top. including Rank.
$r .= "";
$r .= $headers;
$r .= "
";
$i = 1;
while ($row = mysql_fetch_assoc($result)) {
$rowcontent = '';
$mapid = $row['mapID'];
$solution = $row['solution'];
$r .= "";
$r .= "$i | ";
$r .= '' . $row['Name'] . ' | ';
$r .= '' . $row['Moves'] . ' | ';
$r .= '' . $row['Timetaken'] . ' | ';
$r .= "
";
$i++;
}
$r .= "
";
return $r;
}
function mysql_field_array( $query ) {
$field = mysql_num_fields( $query );
for ( $i = 0; $i < $field; $i++ ) {
$names[] = mysql_field_name( $query, $i );
}
return $names;
}
// $sql = 'select columnname etc'
// $result = mysql_query($sql);
// while ($data[] = mysql_fetch_row($result));
// $data[1]['columnname'] == 'my data';
displayPastMaze(1, 'Simple', $daysago);
displayPastMaze(2, 'Normal', $daysago);
displayPastMaze(3, 'Complex', $daysago);
displayPastMaze(4, 'Special', $daysago);
?>
echo $tStats;?>
echo $yStats;?>
echo $wStats;?>
echo $mStats;?>