我正在尝试创建一个表来显示我的数据库中的用户,并且由于某种原因它回显了0个结果。我的数据库中有超过40,000个条目,所以我的PHP代码肯定有问题,但我不知道在哪里。
<?php
require 'session.php';
require 'header.php';
include 'database.php';
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM clients ORDER BY time_edit DESC LIMIT 45";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table border=1>";
echo "<tr>";
echo "<th>Name</th>";
echo "<th>ID</th>";
echo "<th>IP</th>";
echo "<th>Connections</th>";
echo "<th>Last Seen</th>";
echo "<th>Rank</th>";
echo "</tr>";
while($row = $result->fetch_assoc()) {
$name=$row['name'];
$id=$row['id'];
$ip=$row['ip'];
$connections=$row['connections'];
$seen=$row['time_edit'];
$rank=$row['group_bits'];
echo "<tr>";
echo "<td align=center> $name </td>";
echo "<td align=center> $id </td>";
echo "<td align=center> $ip </td>";
echo "<td align=center> $connections </td>";
echo "<td align=center> $seen </td>";
echo "<td align=center> $rank </td>";
echo "</tr>";
}
echo "</table>";
} else {
echo "0 results";
}
$conn->close();
?>