P粉4516148342023-08-28 00:31:38
You can use the following query to get the total number of records in the database
$query = 'SELECT count(*) as total FROM song';
Used to check whether the maximum value is reached
<? if ($page*$recordsPerPage < $total) : ?> <a href="page/details.php?id=<?= $id + 1 ?>">下一页</a>
Full example of hiding next page
$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();