我想将数据库中的表数据拆分到不同的页面,到目前为止一切都很好,但当我尝试在url末尾添加(?page=)时,它不起作用,它是一个wordpress页面,所以url是(www.example.com/page),当我在它传递给我的url(www.example.com/page/2)的末尾添加例如(?page=)时,但数据仍然相同,我限制它在一个页面中显示4条记录。
下面是从db中获取数据的代码,将它们显示在表中并限制它们:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "players";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$start = intval($_GET[\'start\']);
$limit = 4;
$sql = "SELECT name, id, connections, first_seen, last_seen FROM players ORDER BY id LIMIT {$start}, {$limit}";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "<tr><td>".$row["name"]."</td><td>".$row["id"]."</td><td>".$row["connections"]."</td><td>".$row["first_seen"]."</td><td>".$row["last_seen"]."</td></tr>";
}
echo "</table>";
}
else {
echo "0 results";
}
$conn->close();
?>