I have a simple navigation php script which works ok.
The only problem is that I need to find a way to display the pagination links on top of the page instead of the bottom.
So for me a newb, it seems impossible since I have to show the pagination links before the actual navigation variables are being declared.
Can this be done?
Here is the script:
<?
$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>';
}
?>
When I do anything in PHP I do the following
You may also want to look into frameworks like smarty that separate the logic from the template designs. PHP is really a templating language in itself but I actually quite like using smarty.