我正在csgo的bhop服务器中列出最佳时间的前十名。所有时间都存储在数据库中,但问题是每次用户获得新时间时都会添加新行。使用我现在的代码,它显示了所有时间的前十个列表,我希望它只显示每个用户一个结果(最好的一个)
我目前的代码:
<div id="content">
<table cellspacing="0">
<h1 align="center">bhop_eazy_csgo</h1>
<tr><th>Place</th><th>Name</th><th>Time</th></tr>
<?php
$i = 1;
$con=mysqli_connect("localhost","root","*******","timer");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM round WHERE map = 'bhop_eazy_csgo' ORDER BY time LIMIT 0, 10");
while($row = mysqli_fetch_array($result)) {
echo "<tr><td>" . ($i) . "</td><td>" . $row['name'] . "</td> <td>" . gmdate("i:s", $row['time']) . "</td></tr>";
$i++;
}
mysqli_close($con);
?>
</table>
</div>
外观如何:
http://gyazo.com/3653ec8a87fbf68c4137b67b75e20f8d
修改
现在它看起来像这样:
1 Wildmine 00:49
2 Wildmine 00:50
3 Wildmine 01:02
4 【J @ RR3?一点12分
我希望它看起来像这样:
1 Wildmine 00:49
2?J @ rr3? 01:12
感谢Michael Wagner帮助我开展工作:)
$result = mysqli_query($con,"
SELECT DISTINCT name n, (
SELECT time
FROM round
WHERE map = 'bhop_eazy_csgo'
AND name = n
ORDER BY time
LIMIT 1
) AS time
FROM round
WHERE map = 'bhop_eazy_csgo'
ORDER BY time
LIMIT 0 , 10
");
while($row = mysqli_fetch_array($result)) {
echo "<tr><td>" . ($i) . "</td><td>" . $row['n'] . "</td> <td>" . gmdate("i:s", $row['time']) . "</td></tr>";
$i++;
}
答案 0 :(得分:3)
试试这个:
SELECT DISTINCT name n, (
SELECT time
FROM round
WHERE map = 'bhop_eazy_csgo'
AND name = n
ORDER BY time
LIMIT 1
) AS time
FROM round
WHERE map = 'bhop_eazy_csgo'
ORDER BY TIME
LIMIT 0 , 10