scores.php
Go to the documentation of this file.00001 <?php
00002 require_once('./database.php');
00003 import_request_variables("g", "g_");
00004
00005 function query($query) {
00006 global $handle, $database;
00007 $res = mysql($database, $query, $handle);
00008 if (mysql_errno() > 0)
00009 echo mysql_errno().": ".mysql_error()." ($query)<br>";
00010 return $res;
00011 }
00012
00013 $gameIDs = array();
00014 $res = query("SELECT * FROM games");
00015 while ($row = mysql_fetch_assoc($res)):
00016 $gameIDs[$row["title"]] = $row["gameID"];
00017 $titles[$row["gameID"]] = $row["fulltitle"];
00018 endwhile;
00019 mysql_free_result($res);
00020
00021 if (!isset($gameIDs[$g_game])):
00022 print("<span class=\"wichtig\">Fehler:</span> Unbekanntes Spiel.");
00023 exit();
00024 endif;
00025
00026 $gameID = $gameIDs[$g_game];
00027 if (isset($g_name, $g_category, $g_points)):
00028 query("INSERT highscore VALUES(0, $gameID, '$g_category', $g_points, '$g_name', '$g_instance', '')");
00029 exit();
00030 endif;
00031
00032 if (isset($g_top)):
00033 $res = query("SELECT * FROM highscore WHERE gameID='$gameID' ORDER BY category, points DESC, id");
00034 $cat = "";
00035 while ($row = mysql_fetch_assoc($res)):
00036 if ($row[category] != $cat):
00037 if ($cat != ""):
00038 echo "\n";
00039 endif;
00040 $cat = $row[category];
00041 echo "$cat $row[name],$row[instance],$row[points]";
00042 $count = $g_top-1;
00043 else:
00044 if ($count > 0):
00045 echo ":$row[name],$row[instance],$row[points]";
00046 $count--;
00047 endif;
00048 endif;
00049 endwhile;
00050 exit();
00051 endif;
00052
00053 $res = query("SELECT DISTINCT category FROM highscore WHERE gameID=$gameID ORDER BY category");
00054 if (mysql_num_rows($res) == 0):
00055 print("Es sind momentan keine Einträge für dieses Spiel vorhanden.");
00056 exit();
00057 endif;
00058
00059 ?>
00060 <form method="get" action="scores.php">
00061 <input type="hidden" name="game" value="<?php echo htmlentities($g_game)?>"/>
00062 <h2>Bestenliste für
00063 <select name="category" onchange="this.form.submit()" style="font-weight:bold;font-size:0.9em;padding:0;margin:0;">
00064 <?php
00065 $found = false;
00066 while ($row = mysql_fetch_array($res)):
00067 $cat = $row["category"];
00068 if ($g_category==$cat)
00069 $found = true;
00070 echo "<option value=\"$cat\"".($g_category==$cat ? " selected=\"selected\"" : "").">$cat</option>\n";
00071 endwhile;
00072 if (!$found)
00073 $g_category = mysql_result($res, 0, "category");
00074 mysql_free_result($res);
00075 ?>
00076 </select>
00077 </h2>
00078 </form>
00079
00080 <table>
00081 <tr>
00082 <th>Platz</th>
00083 <th>Punkte</th>
00084 <th>Name</th>
00085 </tr>
00086 <?php
00087 $res = query("SELECT * FROM highscore ".
00088 "WHERE gameID='$gameID' AND category='$g_category' ORDER BY points DESC, id");
00089 $i = 1;
00090 while ($row = mysql_fetch_assoc($res))
00091 echo "<tr class=\"".($i%2 ? "odd" : "even")."\"><td>".$i++."</td><td>$row[points]</td><td>$row[name]</td></tr>\n";
00092 mysql_free_result($res);
00093 ?>
00094 </table>