在我的网站上,将仅显示数据库中的8个数据。如果用户单击按钮,将显示其余结果。我使用分页进行此工作。分页工作正常,仅显示数据库中的8个数据。如果单击所有按钮,则所有数据都将可见。当我单击所有按钮时,我可以看到。 all page number
但是当我单击1或2或只是访问尺寸时,我只会看到页面1 button and all button
代码:
//pagination
$results_per_page = 8;
$number_of_results = $audio->num_rows;
$number_of_pages = ceil($number_of_results / $results_per_page);
$page_all = 0;
$page = 1;
if (isset($_GET['page_all'])) {
$page = 1;
$page_all = 1;
$results_per_page = $number_of_results;
} else {
if (!isset($_GET['page'])) {
$page = 1;
} else {
$page = $_GET['page'];
}
}
$this_page_first_result = ($page - 1) * $results_per_page;
$sql2 = 'SELECT * FROM gallery_audio WHERE del_status=0 LIMIT ' .
$this_page_first_result . ',' . $results_per_page;
$all_audio = $conn->query($sql2);
按钮代码
<div class="row">
<?php
// display the links to the pages
$next = $page + 1;
$previous = $page - 1;
for ($page = 1; $page <= $number_of_pages; $page++) {
echo '<a style="color:white;" class="btn btn-danger pb" href="?page=' . $page . '">' . $page . '</a> ';
}
echo '<a style="color:white;" class="btn btn-danger pb" href="?page_all=' . 1 . '">' . 'all' . '</a> ';
?>
</div>