在PHP上反转页面导航

时间:2010-03-30 20:33:09

标签: php navigation reverse

有人可以帮我扭转这个PHP页面导航吗?

当前脚本设置显示以下格式:[0] | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 ... 14•转发> •结束>>>

但是我真的需要它来反转这种格式:[14] | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 ... 0•返回> •开始>>>

这是PHP代码:

<?
$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
?>

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:0)

我找到了问题的解决方案。以下是反向页面导航的链接:php page navigation by serial number