Heim > Fragen und Antworten > Hauptteil
P粉4516148342023-08-28 00:31:38
你可以使用以下查询来获取数据库中的总记录数
$query = 'SELECT count(*) as total FROM song';
用于检查是否达到最大值
<? if ($page*$recordsPerPage < $total) : ?> <a href="page/details.php?id=<?= $id + 1 ?>">下一页</a>
隐藏下一页的完整示例
$servername = "localhost"; $username = "root"; $password = ""; $dbname = "test2"; // 创建连接 $conn = new mysqli($servername, $username, $password, $dbname); // 检查连接 if ($conn->connect_error) { die("连接失败: " . $conn->connect_error); } if (!isset($_GET['id'])) { $id = 1; } else { $id = (int)$_GET['id']; } $recordsPerPage = 10 ; // $query = 'SELECT * FROM song WHERE 1 LIMIT ' . (($id - 1) * $recordsPerPage) . ' ' . $recordsPerPage; // 这里需要处理歌曲数据的获取 $sql = "select count(*) as total FROM songs"; $result = $conn->query($sql); $data = $result->fetch_assoc(); if ($id*$recordsPerPage < (int)$data["total"]) echo "<a href='page/details.php?id=". ($id+1) ."'>下一页</a>"; $conn->close();