gpt4 book ai didi

php - 排名更新问题

转载 作者:行者123 更新时间:2023-11-29 13:23:20 25 4
gpt4 key购买 nike

我有这段代码,它给出了数据库的输出,现在我想根据TeamPoints对其进行排序。得分较高的球队获得第一名。我如何实现它。

我一直在尝试在数据库中添加一个TeamRank字段,该字段通过递增或递减来更新团队排名。但它不起作用,所以我决定按点对它们进行排序,但现在我面临着按升序排列它们的问题。

<?php
$con=mysqli_connect("", "", ", "");

// Check connection:
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

mysqli_query($con,"CREATE VIEW Rankings AS
SELECT TeamID, TeamName, TeamLeader, TeamEmail, P_1, P_2, P_3, P_4, P_5, S_1, S_2, TeamWins, TeamLoss, TeamPoints
FROM team
WHERE TeamID>0");

$result = mysqli_query($con,"SELECT * FROM team");

echo "<table border='1'>
<tr>
<th>TeamID</th>
<th>TeamName</th>
<th>TeamLeader</th>
<th>TeamEmail</th>
<th>Player #1</th>
<th>Player #2</th>
<th>Player #3</th>
<th>Player #4</th>
<th>Player #5</th>
<th>Subsitute #1</th>
<th>Subsitute #2</th>
<th>Total Wins</th>
<th>Total Losses</th>
<th>Total Points</th>
</tr>";

while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['TeamID'] . "</td>";
echo "<td>" . $row['TeamName'] . "</td>";
echo "<td>" . $row['TeamLeader'] . "</td>";
echo "<td>" . $row['TeamEmail'] . "</td>";
echo "<td>" . $row['P_1'] . "</td>";
echo "<td>" . $row['P_2'] . "</td>";
echo "<td>" . $row['P_3'] . "</td>";
echo "<td>" . $row['P_4'] . "</td>";
echo "<td>" . $row['P_5'] . "</td>";
echo "<td>" . $row['S_1'] . "</td>";
echo "<td>" . $row['S_2'] . "</td>";
echo "<td>" . $row['TeamWins'] . "</td>";
echo "<td>" . $row['TeamLoss'] . "</td>";
echo "<td>" . $row['TeamPoints'] . "</td>";
echo "</tr>";
}

echo "</table>";
mysqli_close($con);
?>

最佳答案

这是您要找的吗?

SELECT  TeamID,TeamName,TeamLeader,TeamEmail,P_1,P_2,P_3,P_4,P_5,S_1,S_2,TeamWins,TeamLoss,TeamPoints
FROM team
where TeamID>0
ORDER BY TeamPoints DESC;

关于php - 排名更新问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20476988/

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