开发者

Reversing page navigation on PHP

Can anyone help me with reversing this PHP page navigation?

Current script setting shows this format: [0] |开发者_StackOverflow 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
?>


for ($i=$end; $i>$start; $i--) {
    echo "  ";
    if ($i==$page) {
        echo "[";
     } else {
        echo "<a href=\"?page=$i\">";
    }
 //othercode
}


I found the solution for my question. Here is a link to reversed page navigation: php page navigation by serial number

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜