我为我的网站制作了这个脚本。
它有效,除了有一个小问题。
你可以无限前进
您可以在无限循环中单击“下一页”
由于某种原因,当我回显$ num_pages时,我得到1 0_0
如何修复“infinie nexting” - 我对该问题的奇怪定义:)
<?php
$per_page = 4;
$start = 1;
if(!isset($_GET['page'])) {
$page = 1;
} else {
$page = $_GET['page'];
}
if($page <= 1) {
$start = 1;
$page = 1;
} else {
$start = $page * $per_page - $per_page;
}
$next = $page+1;
$previous = $page-1;
$GetAllComments = $con->query("SELECT * FROM comments LIMIT $start, $per_page");
$num_rows = $GetAllComments->num_rows;
$num_pages = $num_rows / $per_page;
while($GAC = $GetAllComments->fetch_object()) {
echo "<div class='well'> <h3>". $GAC->Title. "</h3>
". $GAC->Content. " <hr /> <em> Posted By ". $GAC->PosterName ." </em>
</div>";
}
$pagen = $page+1;
$pagep = $page-1;
echo "
<div class='pagination'>
<ul>
";
if($page > 1) {
echo "
<li><a href='?page=$previous'>".$pagep."</a> </li>
";
}
echo "
<li class='disabled'><a href='#'>$page</a></li>
";
echo "
<li> <a href='?page=$next'>" . $pagen . "</a></li>
</ul>
</div>
";
答案 0 :(得分:0)
我会将显示放在for循环中:
for($i = 1; $i <= $num_pages; $i++)
{
enter code here
}
这样,它将重复多个页面的num_pages,而不再是。