正如主题所说,添加两个数据库列哇显示结果为ORDER BY DESC LIMIT 20
在这里,我得到了一个效果很好的代码,它显示了前20名富有玩家的结果。
<div class="container div-table" style="padding-top:3%">
<div class="parallax-bg" data-stellar-background-ratio="0.5" data-stellar-vertical-offset="-150"></div>
<div class="parallax-overlay"></div>
<div class="parallax-inner text-center">
<div class="col-sm-4 col-md-11 feature">
<div class="media-object fa fa-usd"></div>
<div class="media-body">
<h4 class="media-heading">Top 20 Richest Players</h4>
</div>
</div>
<table class="table table-bordered">
<thead>
<td><h5>Rank</h5></td>
<td><h5>Username</h5></td>
<td><h5>Money</h5></td>
<td><h5>Last Login</h5></td>
</thead>
<?php
$query = $koneksi->prepare("SELECT `user`, `money`, `LastOnlineDate` FROM `playerdata` WHERE `banned`=0 ORDER BY `money` DESC LIMIT 20");
$query->execute();
if($query->rowCount() == 0)
{
echo "<tr><td colspan='6'><small>No rows found</small></td></tr>";
}
$dollar = 0;
while($data = $query->fetch())
{
$dollar++;
echo "<tr><td>".$dollar."</td>";
echo "<td>".$data['user']."</td>";
echo "<td>".$data['money']."</td>";
echo "<td>".$data['LastOnlineDate']."</td></tr>";
}
?>
</table>
</div>
</div>
正如您所看到的那样,它只显示money
,但我想显示添加Bank
列的结果。
我已尝试过这段代码,即使它是愚蠢的
$query = $koneksi->prepare("SELECT `user`, `money`, `Bank`, `LastOnlineDate` FROM `playerdata` WHERE `banned`=0 ORDER BY `money` + `Bank` DESC LIMIT 20");
答案 0 :(得分:2)
要在sql中添加两列,请使用加号。
select money + bank as total
, etc
order by total desc
答案 1 :(得分:1)
我认为 CONCAT()就是你要找的:
SELECT CONCAT(`money`, '', `Bank`), etc FROM `playerdata` ...