2 回答
TA贡献1765条经验 获得超5个赞
将排名部分添加到表中
<tr>
<th>Rank</th>
<th>User</th>
<th>clicks</th>
</tr>
为每个结果添加排名
<td>
<?php include 'conn.php';
$sql = "select user, count(*) duplicates from users group by user order by duplicates desc";
$result = $conn->query($sql);
$rank = 1;
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo $rank. "<br>";
$rank++;
}
}
?>
</td>
完整代码
<table align="center" style="width:50%">
<tr>
<th>Rank</th>
<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);
$rank = 1;
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo $rank. "<br>";
$rank++;
}
}
?>
</td>
<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>";
}
}
?>
</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>";
}
}
$conn->close();
?></td>
</tr>
</table>
TA贡献1942条经验 获得超3个赞
使用 javascript:
<script type="text/javascript">
var nb = document.getElementsByClassName("number");
for (var i = 0; i < nb.length; i++) {
nb[i].innerHTML = (i+1)+".";
}
</script>
<table align="center" style="width:50%">
<tr>
<th>User</th>
<th>clicks</th>
</tr>
<tr>
<td class="number">
<?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>
- 2 回答
- 0 关注
- 92 浏览
添加回答
举报