Posted By

fackz on 05/07/09


Tagged

results pagination


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

fackz
nkrstevski
jfherring
vali29
BrianCoyDesign


simple pagination


 / Published in: PHP
 

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.

  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  

You need to login to post a comment.