simple pagination


/ Published in: PHP
Save to your folder(s)

Couldent find a pre-made function with a simple pagination.

$curent_page Is what page number you are currently on.
$totalcontent Is how many rows you have in your database
$perpage Is how many rows you display per page.


Copy this code and paste it in your HTML
  1. <?php
  2. function dopages($curent_page, $totalcontent, $perpage){
  3. $totalpages = $totalcontent / $perpage;
  4.  
  5. if($curent_page !== 1){
  6. $preid = $curent_page - 1;
  7. $output .= '<a href="'.$preid.'">Previous</a> ';
  8. }
  9.  
  10. while ( $counter <= $totalpages ) {
  11. if($counter == $curent_page){
  12. $output .= '<a href="'.$counter.'"><b>'.$counter.'</b></a> ';
  13. }else {
  14. $output .= '<a href="'.$counter.'">'.$counter.'</a> ';
  15. }
  16. $counter = $counter + 1;
  17. }
  18.  
  19. if($curent_page !== $totalpages){
  20. $neid = $curent_page + 1;
  21. $output .= '<a href="'.$neid.'">Next</a> ';
  22. }
  23.  
  24.  
  25. return $output;
  26. }
  27. ?>
  28.  
  29. //usage
  30. <? echo dopages(1, 80, 20); ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.