我有这部分代码用于我的分页,向后显示记录。它运作良好,但只在24页测试。必须进行调整以支持更多(100 +)。
寻呼机看起来像
window.onload = function () {
document.querySelector(".button.wc-backward").onclick = function() {
var URLstring = document.referrer; // works fine
window.location.href = URLstring; // ref unchanged
setTimeout(function () {
window.location.href = URLstring; },100); // same result
return false;
}
}
我的代码:
24 23 22 21 20 (current 19) 18 17 16 15 14 ... 2 1
24 23 ... 14 13 12 11 10 (current 9) 8 7 6 5 4 ... 2 1
24 23 ... 11 10 9 8 7 (current 6) 5 4 3 2 1
有什么建议吗?非常感谢你提前!
答案 0 :(得分:1)
我不确定但是尝试使用此循环
for ($counter = $lpm1 - $adjacents; $counter - $adjacents > 2; $counter--)
如果它返回错误的数字但反转的顺序是正确的,那么将结果发布在这个答案中我将尝试思考如何解决它
答案 1 :(得分:0)
<?php
$result = $mysqli->query("SELECT id FROM table");
$total_results = $result->num_rows;
$result->close();
/* Setup vars for query. */
$targetpage = "moving-articles";
$limit = 5;
$adjacents = 5;
$lastpage = ceil($total_results/$limit);
$page = $_GET['page'];
if( $page)
$start = ($page - 1) * $limit;
else
$start = ($lastpage - 1) * $limit;;
/* Get data. */
$sql = $mysqli->query("(SELECT * FROM table ORDER BY datestamp LIMIT $start, $limit) ORDER BY datestamp DESC");
if ($page == '') $page = $lastpage; //if no page var is given, default to last page (as first page)
$prev = $page - 1; //previous page is page - 1
$next = $page + 1; //next page is page + 1
$lpm1 = $lastpage - 1;
/* Draw the pagination object. */
$pagination = "";
if($lastpage > 1)
{
$pagination .= "
<div class='pagination'>";
/* Next Button */
if ($page < $lastpage)
$pagination.= "<a href='$targetpage/page/$next/'>« next</a>";
else
$pagination.= "<span class='disabled'>« next</span>";
if ($lastpage < $adjacents * 4) //not enough pages to bother breaking it up
{
/* Backwards Pagination */
for ($counter = $lastpage; $counter > 0; $counter--) {
if ($counter == $page)
$pagination.= "<span class='current'>$counter</span>";
else
$pagination.= "<a href='$targetpage/page/$counter/'>$counter</a>";
}
}
else if($lastpage > $adjacents * 4) //enough pages to hide some
{
//close to beginning; only hide later pages
if($page > $lastpage - $adjacents * 2)
{
for ($counter = $lastpage ; $counter > abs(($adjacents * 2) - $lastpage) - 1; $counter--)
{
if ($counter == $page)
$pagination.= "<span class='current'>$counter</span>";
else
$pagination.= "<a href='$targetpage/page/$counter/'>$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href='$targetpage/page/2/'>2</a>";
$pagination.= "<a href='$targetpage/page/1/'>1</a>";
}
//in middle; hide some front and some back
else if($page <= $lastpage - $adjacents * 2 && $page > $adjacents * 2)
{
$pagination.= "<a href='$targetpage/page/$lastpage/'>$lastpage</a>";
$pagination.= "<a href='$targetpage/page/$lpm1/'>$lpm1</a>";
$pagination.= "...";
for ($counter = $page + $adjacents; $counter > $page - $adjacents - 1 ; $counter--)
{
if ($counter == $page)
$pagination.= "<span class='current'>$counter</span>";
else
$pagination.= "<a href='$targetpage/page/$counter/'>$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href='$targetpage/page/2/'>2</a>";
$pagination.= "<a href='$targetpage/page/1/'>1</a>";
}
//close to end; only hide early pages
else
{
$pagination.= "<a href='$targetpage/page/$lastpage/'>$lastpage</a>";
$pagination.= "<a href='$targetpage/page/$lpm1/'>$lpm1</a>";
$pagination.= "...";
for ($counter = ($adjacents * 2) +1 ; $counter >= 1; $counter--)
{
if ($counter == $page)
$pagination.= "<span class='current'>$counter</span>";
else
$pagination.= "<a href='$targetpage/page/$counter/'>$counter</a>";
}
}
}
/* Previous Button */
if ($page > $counter - 1)
$pagination.= "<a href='$targetpage/page/$prev/'>previous »</a>";
else
$pagination.= "<span class='disabled'>previous »</span>";
$pagination.= "</div>";
}
?>