/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function getResultPaging($perPage, $currPage, $total) { $paging = new stdClass; // get text $startRec = ($perPage * ($currPage - 1)) + 1; $paging->text = "Viewing records $startRec–$endRec of $total"; // do we have a search string to append to each paging link? } 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) { } else { } } else { } // 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>'; } $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; }