php通过序列号进行页面导航

发布于 2024-08-29 03:33:37 字数 1966 浏览 3 评论 0原文

任何人都可以帮助这个 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)我想当此脚本显示链接但相反时,按正常顺序链接到实际页码。

真的需要帮助解决这个问题!提前致谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

素衣风尘叹 2024-09-05 03:33:37

一位程序员帮助我完成了上述脚本。这是 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 查询并使用 ORDER BY id DESC。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文