Revision: 39531
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at January 18, 2011 04:31 by kendsnyder
Initial Code
function getResultPaging($perPage, $currPage, $total) { $paging = new stdClass; // get text $startRec = ($perPage * ($currPage - 1)) + 1; $endRec = min($total, $perPage * $currPage); $totalPages = ceil($total / $perPage); $paging->text = "Viewing records $startRec–$endRec of $total"; $paging->links = array(); // do we have a search string to append to each paging link? if (($searchName = trim(@$_REQUEST['search']))) { $searchString = "&search=" . rawurlencode($searchName); } else { $searchString = ''; } $_SESSION['last-search'] = '?page=' . $currPage . $searchString; // get pages that should be listed if ($currPage > 5 && $totalPages > 10) { $posFromLast = $totalPages - $currPage; if ($posFromLast >= 5) { $pages = range($currPage - 4, $currPage + 5); } else { $pages = range($currPage - 9 + $posFromLast, $totalPages); } } else { $pages = range(1, $totalPages > 10 ? 10 : $totalPages); } // prev link $paging->links[] = $currPage > 1 ? '<a class="item prev-next prev" href="?page='.($currPage-1).$searchString.'"><span class="quo">«</span> Prev</a>' : '<span class="item prev-next prev inactive"><span class="quo">«</span> Prev</span>'; if ($pages[0] != 1) { $paging->links[] = '<span class="item elipses">...</span>'; } // regular links foreach ($pages as $page) { $paging->links[] = $currPage == $page ? '<span class="item inactive current">'.$page.'</span>' : '<a class="item" href="?page='.$page.$searchString.'">'.$page.'</a>'; } if ($pages[count($pages) - 1] != $totalPages) { $paging->links[] = '<span class="item elipses">...</span>'; } // next link $paging->links[] = $currPage < $totalPages ? '<a class="item prev-next prev" href="?page='.($currPage+1).$searchString.'">Next <span class="quo">»</span></a>' : '<span class="item prev-next prev inactive">Next <span class="quo">»</span></span>'; return $paging; }
Initial URL
Initial Description
Initial Title
SQL results pager HTML
Initial Tags
sql, html
Initial Language
PHP