我有一個簡單的導航php腳本,它工作正常。 唯一的問題是我需要找到一種方法來在頁面頂部而不是底部顯示分頁鏈接。 因此,對於我來說一個newb,似乎不可能,因爲我必須在實際導航變量被聲明之前顯示分頁鏈接。頁面頂部的分頁鏈接,在實際腳本之前
可以這樣做嗎?
下面是腳本:
<?
$numrows = '600';
$rowsperpage = 20;
$totalpages = ceil($numrows/$rowsperpage);
if ($currentpage > $totalpages){ $currentpage = $totalpages; }
if ($currentpage < 1){ $currentpage = 1; }
$offset = ($currentpage - 1) * $rowsperpage;
HERE I query the data from the table and basically fill in the page.
Now starts the pagination links:
$range = 3;
if ($currentpage > 1) {
echo '<a href="'.$site_current.'/'.$slug.'/">First</a>';
}
$prevpage = $currentpage - 1;
echo '<a href="'.$site_current.'/'.$slug.'/'.$prevpage.'/">Previous</a>';
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
if (($x > 0) && ($x <= $totalpages)) {
if($x == $currentpage){
echo '<span class="current">'.$x.'</span>';
} else {
echo '<a href="'.$site_current.'/'.$slug.'/'.$x.'/">'.$x.'</a>';
}
}
}
if ($currentpage != $totalpages){
$nextpage = $currentpage + 1;
echo '<a href="'.$site_current.'/'.$slug.'/'.$nextpage.'/">Next</a>';
echo '<a href="'.$site_current.'/'.$slug.'/'.$totalpages.'/">Last</a>';
}
?>
將您顯示的內容與您的邏輯分開。在迴應任何東西之前,計算出你想在變量中顯示什麼。然後,當您獲得所有需要的信息時,請按照最有意義的順序迴應結果。 – MyStream 2012-07-12 21:53:43
爲什麼你引用'$ numrows'?這是一個數字。你將它作爲一個數字來使用。引號只是讓PHP在每次使用它時轉換爲整數。 – 2012-07-12 21:56:28
而不是600有一個變量。 Ty for the coments,只是想通了:)我可以把分頁鏈接放在偏移量下面,然後開始實際的mysql查詢 – webmasters 2012-07-12 21:58:06