2010-04-10 110 views
1

任何人都可以幫助在這個PHP頁面導航腳本開關計數正常序列號?在這個腳本中有一個名爲「PAGE_ID」變種 - 我想這個變種通過以到店實際頁面鏈接如0,1,2,3,4,5 ...通過序列號的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 = 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)我想通過正常的順序鏈接到真實的頁面編號,當這個腳本顯示鏈接,但相反。

真的需要這個東西的幫助!提前致謝!

+1

請解釋此腳本現在執行什麼操作,哪些操作不起作用以及需要執行哪些操作。我不認爲太多的人願意通過它,並找到所有這一切:) – 2010-04-10 22:21:32

+0

好吧,更新與工作腳本的例子!你可以檢查它!這是顛倒的頁面導航。但我需要像0,1,2,3,4這樣的序列號實際的頁碼!可能在那裏應該有另一個for()在main()內部,它的計數就像$ j ++; ? – ilnur777 2010-04-10 22:33:02

回答

0

我的一位程序員和我的上述腳本一起幫了我。所以這裏是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_ID =通過串行爲了保持真實頁面。所以你可以對數據庫進行SELECT查詢和使用ORDER BY ID DESC。