任何人都可以在此php页面导航脚本中帮助打开正常的序列号吗?在此脚本中,有一个名为“ page_id”的变量-我希望该变量按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;
?>
当此脚本显示链接但相反时,我想按正常顺序链接到此处的xxx(page_id = xxx).
确实需要帮助的东西!提前致谢!
解决方法:
上面的脚本让一位程序员帮助了我.因此,这是在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 =使页码不按相反顺序排列
$page_id =按序列顺序保留实际页面.因此您可以对数据库进行SELECT查询,并使用ID DESC对ORDER BY ID进行查询.