Online hiscore code

Previous topic - Next topic

MrTAToad

As previously mentioned before, I "borrowed" some PHP code from the ClickTeam hiscore routine, and modified it to allow countries.  The code is below (I need to change the Game type section to use an array, but thats no problem) :

Code (glbasic) Select
<?
//****Made by: Jeroen den Haan***Alias's: jeroen84 / Jer'ul****
include_once ("_data.php");
$conn = mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db($db_name,$conn);

$program=$_GET["program"];
$fromProg=$_GET["fromprog"];
$order=$_GET["order"];
$mode=$_GET["gamemode"];
$return="";

switch ($order) {
case "name" :
$sql1 = "SELECT id FROM $db_table WHERE program = '" . $program . "' AND gamemode = '" . $mode . "' ORDER BY name ASC";
$HTM_1 = "<table cellpadding='0' cellspacing='0' border='0' width=" . $table_width . ">
<tbody>
  <tr align=center><td>" . $table_prop . "<tr align=center>
<th bgcolor='" . $t_color . "'>" . $t_font . "#</font></th>
<th bgcolor='" . $t_color . "'>" . $t_font . "Game Mode</font></th>
<th bgcolor='" . $t_color . "'>" . $t_font . "<a href='" . $dis_file . "?sec=1&order=name'>Name</a></font></th>
<th bgcolor='" . $t_color . "'>" . $t_font . "Platform</a></font></th>
<th bgcolor='" . $t_color . "'>" . $t_font . "Country</font></th>
<th bgcolor='" . $t_color . "'>" . $t_font . "Score</font></th>
</tr>";
break;
case "score" :
$sql1 = "SELECT id FROM $db_table WHERE program = '" . $program . "' AND gamemode = '" . $mode . "' ORDER BY score DESC";
$HTM_1 = "<table cellpadding='0' cellspacing='0' border='0' width=" . $table_width . ">
  <tbody>
<tr align=center><td>" . $table_prop . "<tr align=center>
<th bgcolor='" . $t_color . "'>" . $t_font . "#</font></th>
<th bgcolor='" . $t_color . "'>" . $t_font . "Game Mode</font></th>
<th bgcolor='" . $t_color . "'>" . $t_font . "Name</a></font></th>
<th bgcolor='" . $t_color . "'>" . $t_font . "Platform</a></font></th>
<th bgcolor='" . $t_color . "'>" . $t_font . "Country</font></th>
<th bgcolor='" . $t_color . "'>" . $t_font . "<a href='" . $dis_file . "?sec=1'>Score</font></th>
</tr>";
break;

case "platform" :
$sql1 = "SELECT id FROM $db_table WHERE program = '" . $program . "' AND gamemode = '" . $mode . "' ORDER BY platform DESC";
$HTM_1 = "<table cellpadding='0' cellspacing='0' border='0' width=" . $table_width . ">
  <tbody>
<tr align=center><td>" . $table_prop . "<tr align=center>
<th bgcolor='" . $t_color . "'>" . $t_font . "#</font></th>
<th bgcolor='" . $t_color . "'>" . $t_font . "Game Mode</font></th>
<th bgcolor='" . $t_color . "'>" . $t_font . "Name</a></font></th>
<th bgcolor='" . $t_color . "'>" . $t_font . "<a href='" . $dis_file . ">Platform</a></font></th>
<th bgcolor='" . $t_color . "'>" . $t_font . "Country</font></th>
<th bgcolor='" . $t_color . "'>" . $t_font . "Score</font></th>
</tr>";
break;

case "country" :
$sql1 = "SELECT id FROM $db_table WHERE program = '" . $program . "' AND gamemode = '" . $mode . "' ORDER BY countrycode DESC";
$HTM_1 = "<table cellpadding='0' cellspacing='0' border='0' width=" . $table_width . ">
  <tbody>
<tr align=center><td>" . $table_prop . "<tr align=center>
<th bgcolor='" . $t_color . "'>" . $t_font . "#</font></th>
<th bgcolor='" . $t_color . "'>" . $t_font . "Game Mode</font></th>
<th bgcolor='" . $t_color . "'>" . $t_font . "Name</a></font></th>
<th bgcolor='" . $t_color . "'>" . $t_font . "Platform</a></font></th>
<th bgcolor='" . $t_color . "'>" . $t_font . "<a href='" . $dis_file . ">Country</font></th>
<th bgcolor='" . $t_color . "'>" . $t_font . "Score</font></th>
</tr>";
break;

case "gamemode" :
$sql1 = "SELECT id FROM $db_table WHERE program = '" . $program . "' ORDER BY gamemode";
$HTM_1 = "<table cellpadding='0' cellspacing='0' border='0' width=" . $table_width . ">
  <tbody>
<tr align=center><td>" . $table_prop . "<tr align=center>
<th bgcolor='" . $t_color . "'>" . $t_font . "#</font></th>
<th bgcolor='" . $t_color . "'>" . $t_font . "<a href='" . $dis_file . ">Game Mode</font></th>
<th bgcolor='" . $t_color . "'>" . $t_font . "Name</a></font></th>
<th bgcolor='" . $t_color . "'>" . $t_font . "Platform</a></font></th>
<th bgcolor='" . $t_color . "'>" . $t_font . "Country Code</font></th>
<th bgcolor='" . $t_color . "'>" . $t_font . "Score</font></th>
</tr>";
break;

default :
die("Unknown order code");
};

$result1 = mysql_query($sql1);
if ($result1)
{
if (!$fromProg)
{
echo "These are the current hiscores for Spots : The Next Generation";
echo "$HTM_1";
}

$num = 1;
while($r = mysql_fetch_object($result1))
{
$result = mysql_db_query($db_name,"SELECT * from $db_table WHERE id='{$r->id}'");
$resultArray = mysql_fetch_array($result);

switch($program) {
case "spots_tng" :
switch ($resultArray["gamemode"]) {
case 0 : $gamemode = "Arcade Game"; break;
case 1 : $gamemode = "League Game"; break;
case 2 : $gamemode = "Single Game"; break;
case 3 : $gamemode = "Up To 3"; break;
case 4 : $gamemode = "Infection"; break;
case 5 : $gamemode = "5 Second Countdown"; break;
};
};

$name = $resultArray["name"];
$score = $resultArray["score"];
$countrycode = $resultArray["countrycode"];
$platform = $resultArray["platform"];
$m_path="flags/" . strtoupper($countrycode) . ".png width=32 height=18";

if ($sec==1) {
if ($num<=$sec_size) {
$HTML = "
<tr bgcolor='" . $m_color . "' align='center'><td>" . $m_font . $num . "</td>
<td>" . $m_font . $gamemode . "</font></td>
<td>" . $m_font . $name . "</font></td>
<td>" . $m_font . $platform . "</font></td>
<td><img src=" . $m_path . "/></td>
<td>" . $m_font . $score . "</font></td>
</tr>";
}
}
else {
if ($num<=$st_size) {
if ($fromProg) {
$return.=$resultArray["gamemode"] . "," . $name . "," . $score . "," . $countrycode . "," . $platform . "|";
} else {
$HTML = "
<tr bgcolor='" . $m_color . "' align='center'><td>" . $m_font . $num . "</td>
<td>" . $m_font . $gamemode . "</font></td>
<td>" . $m_font . $name . "</font></td>
<td>" . $m_font . $platform . "</font></td>
<td><img src=" . $m_path . "/></td>
<td>" . $m_font . $score . "</font></td>
</tr>";
}
}
$num++;
}

echo "$HTML";
}

if (!$fromProg)
{
if ($sec==1) {
$HTM_2 = "</tbody></table>
</td></tr>
  <tr align=center>
    <th bgcolor='" . $t_color . "'>" . $t_font . "<a href='" . $dis_file . "'>Top" . $st_size . "</a></font></th>
</tr></table>";
} else {
$HTM_2 = "</tbody></table>
</td></tr>
  <tr align=center>
    <th bgcolor='" . $t_color . "'>" . $t_font . "<a href='" . $dis_file . "?sec=1'>Top" . $sec_size . "</a></font></th>
</tr></tbody></table>";
}
echo "$HTM_2";
echo "Most country flags were created by Mark Fennell (www.markfennell.com).  A few others were designed by Graham Bartram";

}
else
{
echo substr($return,0,strlen($return)-1);
}
}
else
{
echo "There are no hiscores to display.  Please come back later!";
}
mysql_close ($conn);
?>


In addition, the routine will only display scores for a specific program, enabling one routine to be used for many programs (although it hasn't been tested yet :) )

This means I could allow host hiscores for those who want it

Ian Price

I came. I saw. I played.