Difference between revisions of "PHP:Pagination"

From wiki
Jump to navigation Jump to search
(Created page with "Category:PHP <syntaxhighlight lang=php> <?php //Paging query results. Finding what paging links to display. Using: // $pageNum (current Page) // $maxPage (maximum pagenu...")
 
(No difference)

Latest revision as of 10:06, 10 June 2019

<?php
//Paging query results. Finding what paging links to display. Using:
//  $pageNum (current Page)
//  $maxPage (maximum pagenumber we can have (ceil($numrows/$rowsPerPage);)

if ($pageNum > 1)
{
   $page  = $pageNum - 1;
   $prev  = " <a href=\"$self?page=$page\">[Prev]</a> ";

   $first = " <a href=\"$self?page=1\">[First Page]</a> ";
}
else
{
   $prev  = '&nbsp;'; // we're on page one, don't print previous link
   $first = '&nbsp;'; // nor the first page link
}

if ($pageNum < $maxPage)
{
   $page = $pageNum + 1;
   $next = " <a href=\"$self?page=$page\">[Next]</a> ";

   $last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
}
else
{
   $next = '&nbsp;'; // we're on the last page, don't print next link
   $last = '&nbsp;'; // nor the last page link
}

// print the navigation link
// echo "Page : ". $page . "  Maxpage : " . $maxPage . "  pageNum : ". $pageNum;

echo $first . $prev . $nav . $next . $last;
?>