傢伙我在這裏和新MySQL的新太..創建排名基本系統和更新排名
所以我想創建用於管理團隊record.The數據庫的數據庫包含了一個名爲團隊表一中設置如下列,
- TeamID
- TeamRank
- TeamName
- TeamWins
- TeamLoss 個
- TeamPoints
所以議程是排名積分的基礎上隊,積分越大越高等級。
<?php
$con = mysqli_connect("", "", "", "");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con, "SET @rownum := 0;
INSERT INTO team(TeamRank, TeamName)
SELECT @rownum := @rownum + 1 AS TeamRank, TeamName
FROM (SELECT SUM(TeamRank)AS TeamRank , TeamName
FROM team
GROUP BY TeamName
ORDER BY TeamRank DESC) as result
ON DUPLICATE KEY UPDATE TeamName = VALUES(TeamName);"
);
echo "<table border='1'>
<tr>
<th>Rank</th>
<th>TeamID</th>
<th>TeamName</th>
<th>Total Points</th>
</tr>";
while ($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['TeamRank'] . "</td>";
echo "<td>" . $row['TeamID'] . "</td>";
echo "<td>" . $row['TeamName'] . "</td>";
echo "<td>" . $row['TeamPoints'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
林recieveing這個錯誤
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result
我在哪裏錯了?如果代碼存在問題,請指導我。
PS [編輯]:我想要做的就是以TeamName,TeamWins,TeamLoss和TeamPoints作爲輸入,並且隨着TeamPoints隊伍的增加/減少,它應該向上/向下移動隊列並顯示排名表。
爲什麼一切都在單引號?即使是PHP標籤:o –
php的報價是我的不好,我認爲我們必須使用引號來插入代碼。 –