我有一个包含游戏分数的多列表。格式是每个分数都附有一个 gameid 编号。然后我找到每个游戏 ID 的最高分并显示它。问题是如果一个游戏被删除,并且gameid号不再连续,它会显示该游戏相同高分的2个。例如,gameid 3 的得分为 5000,gameid 4 的得分为 6000,gameid 5 的得分为 3200。如果我删除 gameid 4,输出将是 5000-3、5000-3、3200-5。我显然没有希望它输出2个相同的分数。下面是我用来执行此操作的 PHP 代码:
<?php
echo '<table cellpadding="0" class="content" cellspacing="0" width="100%" >';
echo '<tr><th>Game</th><th>Initials</th><th>Score</th><th>Date</th></tr>';
include("includes/sqlconnect.inc");
include("includes/functions.php");
$idnum=1;
$allscores = mysql_query("SELECT * FROM scores");
$highid = array(
);
while($row = mysql_fetch_array( $allscores ))
{
$idnums=$row['gameid'];
$highid[]=$idnums;
}
while($idnum<=max($highid))
{
$allscores = mysql_query("SELECT * FROM scores WHERE gameid ='$idnum'");
$array = array(
);
while($row = mysql_fetch_array( $allscores ))
{
$score=$row['score'];
$scoreid=$row['scoreid'];
$array[$scoreid]=$score;
}
$high=doublemax($array);
$nameid = mysql_query("SELECT scoreid,playerid,score FROM scores WHERE scoreid='$high[i]'");
while($row = mysql_fetch_array($nameid))
{
$player=$row['playerid'];
}
$dateid = mysql_query("SELECT scoreid,date FROM scores WHERE scoreid='$high[i]'");
while($row = mysql_fetch_array($dateid))
{
if($row['date']=="")
{
$date="Unknown";
}
else
{
$date=$row['date'];
}
}
$name = mysql_query("SELECT playerid,player_initials FROM players WHERE playerid='$player'");
while($row = mysql_fetch_array($name))
{
$initials=$row['player_initials'];
}
$gamename = mysql_query("SELECT gameid,gamename FROM games WHERE gameid='$idnum'");
while($row = mysql_fetch_array($gamename))
{
$game=$row['gamename'];
}
$idnum++;
echo "<tr>";
echo '<td>'.$game.'</td>';
echo '<td>'.$initials.'</td>';
echo '<td>'.number_format($score).'</td>';
echo '<td>'.$date.'</td>';
echo "</tr>";
}
echo "</table>";
?>