使用php mysql显示前10名球员和每月前10名球员

时间:2010-08-05 09:54:53

标签: php mysql flash

我目前正在为我的游戏网站制作一个高分系统。我已经为此编写了代码。它只显示1-个玩家。当我点击顶级玩家网址时,我希望显示整体顶级玩家,并且当我点击每月顶级玩家网址时,我想显示每月前十名玩家。如何做到这一点。我想要2天。我很震惊。请好好看看这个。代码如下。 敬请参考,请参阅此内容。我需要这样的。有任何想法吗..  http://www.gamesheep.com/highscores.php?id=the-champions-3d-game&table=w

<?php
include_once("_data.php");

$game_name = "test";
$db_table = "newhs_" . $game_name;

$conn = mysql_connect($db_host, $db_user, $db_pass);
mysql_select_db($db_name, $conn);

// Alltime  records...

if ($order=="name") {
 $sql1 = "SELECT id FROM $db_table ORDER BY name ASC";
} else {
 $sql1 = "SELECT id FROM $db_table ORDER BY score DESC";
}
$result1 = mysql_query($sql1);

// Top 10 players....

if($top10 == "name"){
 $sql2 = "SELECT name,score FROM $db_table ORDER BY score DESC LIMIT 10";
} else {
 $sql2 = "SELECT id FROM $db_table ORDER BY score DESC";
}
$result2 = mysql_query($sql2);

// Monthly top 10 players.....

if($mtop10 == "name"){
 $sql3 = "SELECT name, score FROM $db_table WHERE date(dateinfo) = CURdate()";
} else{
 $sql3 = "SELECT id FROM $db_table ORDER BY score DESC";
}
$result3 = mysql_query($sql3);


if (!$flash) {
 if ($order == "name") {
  $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 . "Pos</font></th>
  <th bgcolor='" . $t_color . "'>" . $t_font . "Name</a></font></th>
  <th bgcolor='" . $t_color . "'>" . $t_font . "'>Score</font></th>
  </tr>";
 } else {
  $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 . "Pos</font></th>
   <th bgcolor='" . $t_color . "'>" . $t_font . "Name</a></font></th>
   <th bgcolor='" . $t_color . "'>" . $t_font . "Score</font></th>
  </tr>";
 }
 echo "$HTM_1";
}

$num = 1;

while($r = mysql_fetch_object($result1))
{
 $result = mysql_db_query($db_name, "SELECT name, score from $db_table WHERE id='{$r->id}'");
 $resultArray = mysql_fetch_array($result);
 $id = $resultArray["id"];
 $name = $resultArray["name"];
 $score = $resultArray["score"];
 if ($sec==1) {
  if ($num <= $sec_size) {
   $HTML = "
   <tr bgcolor='" . $m_color . "' align='center'><td>" . $m_font . $num . "</td>
   <td>" . $m_font . $name . "</font></td>
   <td>" . $m_font . $score . "</font></td>
   </tr>";
  echo "$HTML";
  }
 } else {
  if ($num <= $st_size) {
  //echo "&name$num=$name&score$num=$score";
   if ($flash == 1) {
    echo "&name$num=$name&score$num=$score";
   } else {
       echo "&name$num=$name&score$num=$score&num$num=$num&gamename=$game_name";
    $HTML = "
   <tr bgcolor='" . $m_color . "' align='center'><td>" . $m_font . $num . "</td>
    <td>" . $m_font . $name . "</font></td>
    <td>" . $m_font . $score . "</font></td>
    </tr>";
    echo "$HTML";
   }
   $num++;
  }
 }
}

mysql_close ($conn);
?>

1 个答案:

答案 0 :(得分:0)

请考虑添加数据库表内容的预览。 也许表中只有一行?

从快速查看,问题可能出在查询中的情况, 因为毕竟查询工作并从数据库中提取内容。

WHERE date(dateinfo)= CURdate()

顺便说一句,为“每月排名前10位的玩家”查询添加“限制10”。