Guest User

Untitled

a guest
Jan 17th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. <?php
  2. // the page where this paging is used
  3. $page_dom = "index.php";
  4.  
  5. echo "<ul class=\"pagination\">";
  6.  
  7. // button for first page
  8. if ($page > 1) {
  9. echo "<li><a href='{$page_dom}' title='Go to the first page.'>";
  10. echo "First Page";
  11. echo "</a></li>";
  12. }
  13.  
  14. // count all products in the database to calculate total pages
  15. $total_rows = $product->countAll();
  16. $total_pages = ceil($total_rows / $records_per_page);
  17.  
  18. // range of links to show
  19. $range = 2;
  20.  
  21. // display links to 'range of pages' around 'current page'
  22. $initial_num = $page - $range;
  23. $condition_limit_num = ($page + $range) + 1;
  24.  
  25. for ($x = $initial_num; $x < $condition_limit_num; $x++) {
  26. // be sure '$x is greater than 0' AND 'less than or equal to the $total_pages'
  27. if (($x > 0) && ($x <= $total_pages)) {
  28. // current page
  29. if ($x == $page) {
  30. echo "<li class='active'><a href=\"#\">$x <span class=\"sr-only\">(current)</span></a></li>";
  31. }
  32.  
  33. // not current page
  34. else {
  35. echo "<li><a href='{$page_dom}?page=$x'>$x</a></li>";
  36. }
  37. }
  38. }
  39.  
  40. // button for last page
  41. if ($page < $total_pages) {
  42. echo "<li><a href='" . $page_dom . "?page={$total_pages}' title='Last page is {$total_pages}.'>";
  43. echo "Last Page";
  44. echo "</a></li>";
  45. }
  46.  
  47. echo "</ul>";
  48. ?>
Add Comment
Please, Sign In to add comment