Bootstrap Pager




  1. <?
  2. $total_query=30;
  3. $active_page_number=1;
  4. $per_page_display=10;
  5. if(isset($_GET['page-number'])){
  6.     $active_page_number ctype_digit($_GET['page-number'])? $_GET['page-number'] : 1;
  7.     echo "<h1>Page Number " $_GET['page-number'] . "</h1>";
  8.     echo "<br>Per Page Display "$per_page_display;
  9.     echo "<br>Active Page Number "$active_page_number;
  10.     echo "<br>Total Query "$total_query;
  11. }
  12. echo pager("?","page-number=",$total_query,$active_page_number,$per_page_display);
  13. function pager($q,$p="page",$totalRow=30,$currentPage=1,$perPageDisplay=10)
  14. {
  15. $pp="";
  16. $leftDisplay=4;
  17. $rightDisplay=4;
  18. $totalPage=ceil($totalRow $perPageDisplay);
  19. if($currentPage $totalPage)
  20. $currentPage=1;
  21. $lplus=0;
  22. $rplus=0;
  23. if($totalPage 10)
  24. {
  25. for($i=1;$i<=$totalPage;$i++)
  26. if($currentPage == $i)
  27. $pp .= "<li><a href=\"$q$p$i\" class=\"active\"> $i  </a></li>";
  28. else
  29. $pp .= "<li><a href=\"$q$p$i\" > $i  </a></li>";
  30. }
  31. else
  32. {
  33. if($currentPage <= $leftDisplay){
  34. $lplus=$leftDisplay $currentPage;
  35. $l=1;
  36. $rightDisplay $rightDisplay $lplus;
  37. $end="<li><a href=\"$q$p$totalPage\" aria-label=\"Next\"><span aria-hidden=\"true\">&raquo;</span></a></li>";
  38. }
  39. else{
  40. $l=$currentPage $leftDisplay;
  41. $end="<li><a href=\"$q$p$totalPage\" aria-label=\"Next\"><span aria-hidden=\"true\">&raquo;</span></a></li>";
  42. }
  43. if(($currentPage $rightDisplay) >= $totalPage){
  44. $rplus=($currentPage $rightDisplay) - $totalPage;
  45. $r=$totalPage;
  46. $l=$l-$rplus;
  47. $start="<li><a href=\"".$q.$p."1\" aria-label=\"Previous\"><span aria-hidden=\"true\">&laquo;</span></a></li>";
  48. }
  49. else{
  50. $r=$currentPage $rightDisplay;
  51. $start="<li><a href=\"".$q.$p."1\" aria-label=\"Previous\"><span aria-hidden=\"true\">&laquo;</span></a></li>";
  52. }
  53. $pp $start;
  54. for($i=$l;$i<=$r;$i++){
  55. if($currentPage == $i)
  56.  $pp .= "<li class=\"active\"><a href=\"$q$p$i\">$i<span class=\"sr-only\">$i</span></a></li>";
  57. else
  58.  $pp .= "<li><a href=\"$q$p$i\">$i</a></li>";
  59. }
  60. $pp .= $end;
  61. }
  62. return $pp;
  63. }

Leave a Reply

Your email address will not be published. Required fields are marked *