我需要为我正在制作的测验网站设计一个排行榜。我将用户分数存储在名为“user_record”的数据库表中,该表具有以下结构:
'user_id' - varchar(254) -which holds the user id for a particular score
'score' - int(2) -which holds the score
'time' - timesatamp -which has the CURRENT_TIMESTAMP
'date' - date -which has the CURDATE()
现在我需要对当前日期的每个 user_id 的值求和,并按降序显示前 5 个。我有以下代码,但它似乎不起作用。有什么帮助吗?
<table>
<tr>
<th>User Id</th>
<th>Score</th>
</tr>
<?php
include "connection.php";
$w=mysql_query("SELECT user_id,SUM(Score) from score WHERE date=CURDATE() GROUP BY user_id ORDER BY score DESC limit 5");
$b=$row=mysql_fetch_array($w);
while($b)
{
$user_id=$row['user_id'];
$score=$row['score'];
?>
<tr>
<td><?php echo $user_id;?></td>
<td><?php echo $score; ?></td>
</tr>
<?php
}
?>
</table>