我有这张表,它显示来自 mysql 的数据并通过大多数点击对它们进行排序,但我没有 #1 或 #2 等等....这里是代码:
<table align="center" style="width:50%">
<tr>
<th>User</th>
<th>clicks</th>
</tr>
<tr>
<td>
<?php include 'conn.php';
$sql = "select user, count(*) duplicates from users group by user order by duplicates desc";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo $row["user"]. "<br>";
}
} else {
}
?>
</td>
<td>
<?php
include 'conn.php';
$sql = "select user, count(*) AS duplicates from users group by user order by duplicates desc";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo $row["duplicates"]. "<br>";
}
} else {
}
$conn->close();
?></td>
</tr>
</table>
输出在表格中是这样的:
users clicks
user1 3
user2 2
user3 1
但我希望输出为:
rank users clicks
1 user1 3
2 user2 2
3 user3 1
POPMUISE
手掌心