我需要我的电脑游戏从用户总数中获取所有杀伤和死亡人数,然后进行计算,以便将杀伤人数除以死亡人数,然后将总数计入末尾。该比率称为它们的死亡比,或“ KDR”。
<?php
// Create connection
$con=mysqli_connect("ipaddress","user","password","minecraft");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT *, `kills`/`deaths` as `KDR` FROM war_kills ``ORDER BY kills DESC");
echo "<table border='1'>
<tr>
<th>Player</th>
<th>Kills</th>
<th>Deaths</th>
<th>KDR</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['player'] . "</td>";
echo "<td>" . $row['kills'] . "</td>";
echo "<td>" . $row['deaths'] . "</td>";
echo "<td>" . $row['KDR'] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
到目前为止,我们有以下内容:http://gexgaming.com/warstats/index.php
最佳答案
将查询从
SELECT player, kills, deaths, KDR FROM war_kills ORDER BY kills DESC`
至
SELECT player, kills, deaths, kills / deaths as KDR FROM war_kills ORDER BY kills DESC`