Here's my clan's implementation of this:
http://yinyarr.com/Map_Ratings.aspx
I'm using a SQLite3 database instead of MySQL. It's a bit harder this way, but is still quite usable. Here's the code I used, which basically retrieves the database via FTP and then displays the data. Keep in mind I expect very little load on this page so I haven't tested any blocking or issues that arise when multiple people access the page at the same time (hence overlapping FTP downloads).
Also note that this is a big security risk if you store your admin information in the same database as the ratings, since it'll be transferred to your webhost where people could download it. Simple solutions are to separate these databases or protect the file on the server with htaccess (if available).
Code:
<html>
<head>
<title>YinYarr Map Ratings</title>
<style type="text/css">
BODY {
background-color: #2C2A28;
color: #FFFFFF;
font: 9pt Calibri, Arial, san-serif;
line-height: 140%;
}
.mainbar {
margin-top: 1px;
height: 20px;
clear: both;
}
.bar1 {
margin-right: 5px;
background-color: #bb3c3c;
height: 20px;
float: left;
}
.bar2 {
margin-right: 5px;
background-color: #a64a4d;
height: 20px;
float: left;
}
.bar3 {
margin-right: 5px;
background-color: #8c5b64;
height: 20px;
float: left;
}
.bar4 {
margin-right: 5px;
background-color: #716c7a;
height: 20px;
float: left;
}
.bar5 {
margin-right: 5px;
background-color: #5c798b;
height: 20px;
float: left;
}
H2 {
font: 18pt Calibri, Arial, san-serif;
margin-bottom: 2px;
}
</style>
<script type="text/javascript">
function autofitIframe(id) {
if (!window.opera && !document.mimeType && document.all && document.getElementById){
parent.document.getElementById(id).style.height=this.document.body.offsetHeight+"px";
}
else if(document.getElementById) {
parent.document.getElementById(id).style.height=this.document.body.scrollHeight+"px"
}
}
</script>
</head>
<body onload="autofitIframe('ifrm')">
<?php
## Get the remote file and store it
$database = file("ftp://username:pass@ipaddress/path_on_server/orangebox/tf/addons/sourcemod/data/sqlite/sourcemod-local.sq3");
file_put_contents("sourcemod-local.sq3", $database);
## Connect to the database
$maps = array();
$db = new PDO('sqlite:sourcemod-local.sq3');
$result = $db->query("SELECT * FROM map_ratings");
while($row = $result->fetchObject()) {
$maps[$row->map]["$row->rating"]++;
$maps[$row->map]["ratingcount"]++;
$maps[$row->map]["ratingtotal"] += $row->rating;
}
$result = $db->query("SELECT map, AVG(rating) AS ratingaverage, COuNT(rating) AS ratingcount FROM map_ratings GROUP BY map ORDER BY ratingaverage DESC, map");
while($row = $result->fetchObject()) {
## Get this record
$mapname = $row->map;
$ratings = $maps[$mapname];
## This should never happen
if ($ratings["ratingcount"] == 0) {
continue;
}
## Prepare fields
$average = round($ratings["ratingtotal"] / $ratings["ratingcount"], 2);
if (!$ratings["1"]) {
$ratings["1"] = 0;
}
if (!$ratings["2"]) {
$ratings["2"] = 0;
}
if (!$ratings["3"]) {
$ratings["3"] = 0;
}
if (!$ratings["4"]) {
$ratings["4"] = 0;
}
if (!$ratings["5"]) {
$ratings["5"] = 0;
}
## Print record
print "<h2>$mapname</h2>\n";
print "<b>Average Rating:</b> $average<br>\n";
print "<b>Total Ratings:</b> " . $ratings["ratingcount"] . "<br>\n";
?>
<div class="mainbar">
<div class="bar5" style="width:<?=$ratings["5"] / $ratings["ratingcount"] * 500 + 5?>px"></div>
<?=$ratings["5"]?> Excellent
</diV>
<div class="mainbar">
<div class="bar4" style="width:<?=$ratings["4"] / $ratings["ratingcount"] * 500 + 5?>px"></div>
<?=$ratings["4"]?> Good
</diV>
<div class="mainbar">
<div class="bar3" style="width:<?=$ratings["3"] / $ratings["ratingcount"] * 500 + 5?>px"></div>
<?=$ratings["3"]?> Average
</diV>
<div class="mainbar">
<div class="bar2" style="width:<?=$ratings["2"] / $ratings["ratingcount"] * 500 + 5?>px"></div>
<?=$ratings["2"]?> Poor
</diV>
<div class="mainbar">
<div class="bar1" style="width:<?=$ratings["1"] / $ratings["ratingcount"] * 500 + 5?>px"></div>
<?=$ratings["1"]?> Terrible
</diV>
<?php
}
?>
</body>
</html>