<template:code> <?php function renderPagingList($paging) { // Get the current page without the querystring. $currentPage = $_SERVER["PHP_SELF"]; // Looping over the query string is faster than using the preg_replace() function // that was being used previously. $queryString = ""; if (!empty($_SERVER['QUERY_STRING'])) { $params = explode("&", $_SERVER['QUERY_STRING']); $newParams = array(); foreach ($params as $param) { if (strpos($param, "page") === false) { array_push($newParams, $param); } } if (count($newParams) != 0) { $queryString = "&" . htmlentities(implode("&", $newParams)); } } echo "<div class=\"pager\">\n"; echo "<ul>"; if ($paging['pageNum'] > 0) { // Show if not first page //echo "<li class=\"first\"><a href=\"".sprintf("%s?page=%d%s", $currentPage, 0, $queryString)."\">First</a></li>\n"; echo "<li class=\"prev\"><a href=\"".sprintf("%s?page=%d%s", $currentPage, max(0, $paging['pageNum'] - 1), $queryString)."\">Previous</a></li>\n"; } // By default, we'll display 3 on the left and 3 on the right of the current page. // Of course this only applies if those pages are available. $start = max(0, $paging['pageNum'] - 3); $stop = min($paging['totalPages'], $paging['pageNum'] + 3); for ($i = $start; $i <= $stop; $i++) { if ($i == $paging['pageNum']) { echo "<li><a class=\"active\" href=\"".sprintf("%s?page=%d%s", $currentPage, $i, $queryString)."\">".($i + 1)."</a>\n"; } else { echo "<li><a href=\"".sprintf("%s?page=%d%s", $currentPage, $i, $queryString)."\">".($i + 1)."</a></li>\n"; } } if ($paging['pageNum'] < $paging['totalPages']) { // Show if not last page echo "<li class=\"next\"><a href=\"".sprintf("%s?page=%d%s", $currentPage, min($paging['totalPages'], $paging['pageNum'] + 1), $queryString)."\">Next</a></li>\n"; //echo "<li class=\"last\"><a href=\"".sprintf("%s?page=%d%s", $currentPage, $paging['totalPages'], $queryString)."\">Last</a></li>\n"; } echo "</ul>\n"; echo "<p>"; if ($paging['viewAll']) { echo "All Records"; } else { echo "Records " . ($paging['startRow'] + 1) . " to " . min($paging['startRow'] + $paging['perPage'], $paging['totalRows']) . " of " . $paging['totalRows']; } echo "</p>\n"; echo "<p>\n"; echo "<a href=\"".sprintf("%s?page=%s%s", $currentPage, 'all', $queryString)."\">View All</a>\n"; echo "</p>\n"; echo "</div>\n"; } ?> </template:code>
Comments: