Skip to content

Instantly share code, notes, and snippets.

@gsmcwhirter
Forked from anonymous/gist:472797
Created July 12, 2010 17:48
Show Gist options
  • Save gsmcwhirter/472800 to your computer and use it in GitHub Desktop.
Save gsmcwhirter/472800 to your computer and use it in GitHub Desktop.
<?php
$query = "SELECT mapid, kills, games, connections FROM ps_c_map_data ORDER BY games desc";
$result = mysql_query($query)
or die('Sorry, we could not retrieve pending from the database. Please try again.');
$totalmaps = mysql_num_rows($result);
$mapdata = array();
$kpgdata = array();
while ($row=mysql_fetch_array($result, MYSQL_ASSOC))
{
$mapdata[$row['mapid']] = array();
$mapdata[$row['mapid']]['mapid'] = $row['mapid'];
$mapdata[$row['mapid']]['kills'] = (int)$row['kills'];
$mapdata[$row['mapid']]['games'] = (int)$row['games'];
$mapdata[$row['mapid']]['connections'] = (int)$row['connections'];
if($mapdata[$row['mapid']]['games'] != 0)
{
$mapdata[$row['mapid']]['kills_per_game'] = $mapdata[$row['mapid']]['kills'] / $mapdata[$row['mapid']]['games'];
$mapdata[$row['mapid']]['kills_per_game'] = round($mapdata[$row['mapid']]['kills_per_game'],2);
$mapdata[$row['mapid']]['conn_per_game'] = $mapdata[$row['mapid']]['connections'] / $mapdata[$row['mapid']]['games'];
$mapdata[$row['mapid']]['conn_per_game'] = round($mapdata[$row['mapid']]['conn_per_game'],2);
}
else
{
$mapdata[$row['mapid']]['kills_per_game'] = 0.0;
$mapdata[$row['mapid']]['conn_per_game'] = 0.0;
}
$kpgdata[$row['mapid']] = $mapdata[$row['mapid']]['kills_per_game'];
}
array_multisort($kpgdata, SORT_DESC, $mapdata);
foreach($mapdata as $mapid => $row)
{
if ($row['games'] >= 100)
{
$query2 = "SELECT uniqueid FROM ps_map WHERE mapid='$mapid'";
$result2 = mysql_query($query2)
or die('Sorry, we could not retrieve pending from the database. Please try again.');
$row2=mysql_fetch_array($result2, MYSQL_ASSOC);
$map = $row2['uniqueid'];
echo "<tr>\n";
echo "<td>$map</td>\n";
echo "<td>$row['games']</td>\n";
echo "<td>$row['kills_per_game']</td>\n";
echo "<td>$row['conn_per_game']</td>\n";
echo "</tr>\n";
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment