gpt4 book ai didi

php - 需要帮助从数据库(PHP)中仅显示每个用户的一个结果

转载 作者:搜寻专家 更新时间:2023-10-30 22:12:02 25 4
gpt4 key购买 nike

我正在从我的 csgo bhop 服务器中列出最佳时间的前 10 名。所有时间都存储在数据库中,但问题是每次用户获得新时间时都会添加一个新行。使用我现在拥有的代码,它始终显示前十名列表,我希望它只显示每个用户一个结果(最好的一个)

我当前的代码:

<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? 01:12

我希望它看起来像这样:

1 Wildmine 00:49
2 ?J@rr3? 01:12
Thanks to Michael Wagner for helping me getting it working:)

$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++;

最佳答案

试试这个:

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

关于php - 需要帮助从数据库(PHP)中仅显示每个用户的一个结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25445669/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com