du512926 2010-04-10 22:17
浏览 39
已采纳

php页面按序列号导航

Can anyone help in this php page navigation script switch on counting normal serial number? In this script there is a var called "page_id" - I want this var to store the real page link by order like 0, 1, 2, 3, 4, 5 ...

<?
$onpage = 10; // on page

/*
 $pagerecord - display records per page
 $activepage - current page
 $records - total records
 $rad - display links near current page (2 left + 2 right + current page = total 5)
*/

function navigation($pagerecord, $activepage){

$records = 55;
$rad = 4;

if($records<=$pagerecord) return;

$imax = (int)($records/$pagerecord);
if ($records%$pagerecord>0)$imax=$imax+1;

if($activepage == ''){
$for_start=$imax;
$activepage = $imax-1;
}
$next = $activepage - 1; if ($next<0){$next=0;}
$end =0;
$prev = $activepage + 1; if ($prev>=$imax){$prev=$imax-1;}
$start=  $imax;
if($activepage >= 0){
$for_start = $activepage + $rad + 1; 
if($for_start<$rad*2+1)$for_start = $rad*2+1;
if($for_start>=$imax){ $for_start=$imax; }
}
if($activepage < $imax-1){
$str .= ' <a href="?page='.($start-1).'"><<< End</a> <span style="color:#CCCCCC">•</span> <a href="?page='.$prev.'">< Forward</a> | ';
}
$meter = $rad*2+1;  //$rad; ---------------------
for($i=$for_start-1; $i>-1; $i--){
$meter--;
//$line = '|'; if ($meter=='0'){ $line = ''; }
$line = ''; if ($i>0)$line = '|';
if($i<>$activepage){
$str .= " <a href='?page=".$i."&page_id=xxx'>".($i)."</a> ".$line." ";
} else {
$str .= " <strong>[".($i)."]</strong> ".$line." ";
}

if($meter=='0'){ break; }
}
if($activepage > 0){
$str .= " | <a href='?page=".$next."'>Back ></a> <span style='color:#CCCCCC'>•</span> <a href='?page=".($end)."'>Start >>></a> ";
}

return $str;

}

if(is_numeric($_GET["page"])) $page = $_GET["page"];
$navigation = navigation($onpage, $page); // detect navigation

echo $navigation;
?>

Instead xxx here (page_id=xxx) I want to link to real page number by normal order when this script show links but reversed.

Really need help with this stuff! Thanks in advance!

  • 写回答

1条回答 默认 最新

  • doushi1510 2010-04-11 23:48
    关注

    I were helped by one of the programmers with my above script. So here is a worked example of the reversed page navigation on PHP.

    <?
    $onpage = 10; // on page
    
    /*
     $pagerecord - display records per page
     $activepage - current page
     $records - total records
     $rad - display links near current page (2 left + 2 right + current page = total 5)
    */
    
    function navigation($pagerecord, $activepage){
    
    $records = 126;
    $rad = 4;
    
    if($records<=$pagerecord) return;
    
    $imax = (int)($records/$pagerecord);
    if ($records%$pagerecord>0)$imax=$imax+1;
    
    if($activepage == ''){
    $for_start=$imax;
    $activepage = $imax-1;
    }
    $next = $activepage - 1; if ($next<0){$next=0;}
    $end =0;
    $prev = $activepage + 1; if ($prev>=$imax){$prev=$imax-1;}
    $start=  $imax;
    if($activepage >= 0){
    $for_start = $activepage + $rad + 1;
    if($for_start<$rad*2+1)$for_start = $rad*2+1;
    if($for_start>=$imax){ $for_start=$imax; }
    }
    
    $meter = $rad*2+1;  //$rad; ---------------------
    $new_meter = $for_start-1;
    if($activepage < $imax-1){
    $str .= ' <a href="?page='.($start-1).'&page_id='.$end.'"><<< End</a> <span style="color:#CCCCCC">•</span> <a href="?page='.$prev.'&page_id='.($imax-$prev-1).'">< Forward</a> | ';
    }
    for($i=$for_start-1; $i>-1; $i--){
    $meter--;
    //$new_meter++;
    //$line = '|'; if ($meter=='0'){ $line = ''; }
    $line = ''; if ($i>0)$line = '|';
    if($i<>$activepage){
    $str .= " <a href='?page=".$i."&page_id=".($imax-$i-1)."'>".($i)."</a> ".$line." ";
    } else {
    $str .= " <strong>[".($i)."]</strong> ".$line." ";
    }
    
    if($meter=='0'){ break; }
    }
    if($activepage > 0){
    $str .= " | <a href='?page=".$next."&page_id=".($imax-$next-1)."'>Back ></a> <span style='color:#CCCCCC'>•</span> <a href='?page=".($end)."&page_id=".($start-1)."'>Start >>></a> ";
    }
    
    return $str;
    
    }
    
    if(is_numeric($_GET["page"])) $page = $_GET["page"];
    $navigation = navigation($onpage, $page); // detect navigation
    
    echo $navigation;
    ?>
    

    $page = keeps the page number from the reversed order

    $page_id = keeps the real page by serial order. so you can make SELECT queries to database and ORDER BY id DESC use.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘