【发布时间】:2019-03-22 18:14:43
【问题描述】:
我在 mysqli 数据库中有一个带有 auto_increment 列的表,并且想从该表中为每个用户获取数据,无论用户名出现在该表上的任何位置。我想在一个 html 表上显示这个获取的数据,该表应该有从 1 开始的序列号列,并为 html 表中的每一行增加 +1。我发现很难按数字顺序显示我的表格。
我已经通过谷歌搜索并阅读了 Stackoverflow 上的一些类似问题,但找不到解决方案。
<?php $referralList = "SELECT * FROM referrals where sponsor='$username'";
$listResult = mysqli_query($conn,$referralList)or die(mysqli_error());
echo "<table class='table table-bordered table-hover table-striped'>";
echo "<thead><tr><th>№</th><th>Username</th><th>Phone №</th><th>Reg Date</th><th>Total Bonus</th><th>Status</th></tr></thead>";
if (mysqli_num_rows($listResult)<1) {
echo "<em style='color:red;'>You have no referral yet, invite people to start earning extra bonuses </em>";
} else {
while($listRow = mysqli_fetch_array($listResult)) {
$id = $listRow['userid'];
$referral = $listRow['username'];
$referralPhone = $listRow['phoneNumber'];
$regD = $listRow['reg_Date'];
$totalbonus = $listRow['totalbonus'];
if ($listRow['status']==0){
$status='<td style="background-color:hsla(0, 100%, 50%, 0.8)">Suspended</td>';
else if ($listRow['status']==2) {
$status='<td style="background-color:hsla(60, 100%, 50%, 0.8)">On Probe</td>';
}
else if ($listRow['status']==1) {
$status= '<td style="background-color:hsla(120, 100%, 40%, 0.8); color: white;">Active <i class="fa fa-check"></i></td>';
}
else {
$status='<td>Unknown</td>';
}
echo '<tbody><tr><td>', "$id", '</td><td>', "$referral", '</td><td>', "$referralPhone", '</td><td>', "$regD",'</td><td>', "$totalbonus", '</td><b>', "$status", '</b></tr></tbody>';
}
}
echo "</table>";
?>
我希望 html 表有一个序列号列,以从 1、2、3、4、5 等开始的数字顺序排列行
【问题讨论】:
-
这很简单。你几乎明白了。