Reversing page navigation on PHP
Posted
by ilnur777
on Stack Overflow
See other posts from Stack Overflow
or by ilnur777
Published on 2010-03-30T20:33:09Z
Indexed on
2010/03/30
20:43 UTC
Read the original article
Hit count: 610
Can anyone help me with reversing this PHP page navigation?
Current script setting shows this format: [0] | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 ... 14 • Forward > • End >>>
But I really need it to reverse for this format: [14] | 13 | 12 | 11| 10 | 9 | 8 | 7 | 6 ... 0 • Back > • Start >>>
Here is the PHP code:
<?
$onpage = 10; // on page
function page(){
if(empty($_GET["page"])){
$page = 0;
} else {
if(!is_numeric($_GET["page"])) die("Bad page number!");
$page = $_GET["page"];
}
return $page;
}
function navigation($onpage, $page){
//----------------
$countt = 150;
$cnt=$countt; // total amount of entries
$rpp=$onpage; // total entries per page
$rad=4; // amount of links to show near current page (2 left + 2 right + current page = total 5)
$links=$rad*2+1;
$pages=ceil($cnt/$rpp);
if ($page>0) { echo "<a href=\"?page=0\"><<< Start</a> <font color='#CCCCCC'>•</font> <a href=\"?page=".($page-1)."\">< Back</a> <font color='#CCCCCC'>•</font>"; }
$start=$page-$rad;
if ($start>$pages-$links) { $start=$pages-$links; }
if ($start<0) { $start=0; }
$end=$start+$links;
if ($end>$pages) { $end=$pages; }
for ($i=$start; $i<$end; $i++) {
echo " ";
if ($i==$page) {
echo "[";
} else {
echo "<a href=\"?page=$i\">";
}
echo $i;
if ($i==$page) {
echo "]";
} else {
echo "</a>";
}
if ($i!=($end-1)) { echo " <font color='#CCCCCC'>|</font>"; }
}
if ($pages>$links&&$page<($pages-$rad-1)) { echo " ... <a href=\"?page=".($pages-1)."\">".($pages-1)."</a>"; }
if ($page<$pages-1) { echo " <font color='#CCCCCC'>•</font> <a href=\"?page=".($page+1)."\">Forward ></a> <font color='#CCCCCC'>•</font> <a href=\"?page=".($pages-1)."\">End >>></a>"; }
}
$page = page(); // detect page
$navigation = navigation($onpage, $page); // detect navigation
?>
© Stack Overflow or respective owner