Posted By

mus7afa on 06/12/15


Tagged

php pagination


Versions (?)

PHP simple pagination


 / Published in: PHP
 

PHP pagination simple algorithms;

  1. total_page = 10;
  2. $current_page = empty($_GET['page']) ? 1 : $_GET['page'];
  3. $previous_page = $current_page - 1;
  4. $next_page = $current_page + 1;
  5.  
  6. if ($previous_page == 0) {
  7. $previous_page = 1;
  8. }
  9.  
  10.  
  11. if ($next_page > $total_page) {
  12. $next_page = $current_page;
  13. }
  14.  
  15. echo "<a href='test.php?page=1'> First Page </a>";
  16. echo "<a href='test.php?page=$previous_page'> Previous </a>";
  17.  
  18. for ($i=1; $i < $total_page; $i++) :
  19. if ($current_page == $i) {
  20. echo "<a href='test.php?page=$i'> $i - Selected </a>";
  21. }else{
  22. echo "<a href='test.php?page=$i'> $i </a>";
  23. }
  24.  
  25. endfor;
  26.  
  27. echo "<a href='test.php?page=$total_page'> Last Page </a>";
  28. echo "<a href='test.php?page=$next_page'> Next </a>";

Report this snippet  

You need to login to post a comment.