Rumah > Soal Jawab > teks badan
P粉4516148342023-08-28 00:31:38
Anda boleh menggunakan pertanyaan berikut untuk mendapatkan jumlah bilangan rekod dalam pangkalan data
$query = 'SELECT count(*) as total FROM song';
Digunakan untuk menyemak sama ada nilai maksimum tercapai
<? if ($page*$recordsPerPage < $total) : ?> <a href="page/details.php?id=<?= $id + 1 ?>">下一页</a>
Contoh penuh menyembunyikan halaman seterusnya
$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();