我有一个简单的导航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