We Recommend

Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems
Wicked Cool PHP contains a wide variety of scripts to process credit cards, check the validity of email addresses, template HTML, and serve dynamic images and text.


Posted By

Tate on 04/24/08


Tagged


Versions (?)


Who likes this?

3 people have marked this snippet as a favorite

luman
mmccrack
stavelin


Pagination


Published in: PHP 


  1. //Above the loop
  2. $readerItems = $myReader->buildMyItems();
  3. $readerTotal = $readerItems;
  4.  
  5. $page=1;
  6. if (isset($_REQUEST['page']))
  7. $page = $_REQUEST['page'];
  8. $perPage = 30;
  9. $readerItems = array_slice($readerItems, (($page-1)*$perPage), $perPage, true);
  10.  
  11. //Below the loop for the links
  12. $currentPage = 1;
  13. if (isset($_REQUEST['page']))
  14. $currentPage = $_REQUEST['page'];
  15.  
  16. $pages = ceil(count($readerTotal) / $perPage);
  17. if ($currentPage != 1)
  18. echo "<a href='/my/index.php?page=".($currentPage-1)."'>Previous </a> ";
  19. echo 'Page ';
  20. for($x=1; $x<=$pages; $x++) {
  21. if ($x == $currentPage)
  22. echo ($x)." ";
  23. else
  24. echo "<a href='/my/index.php?page=$x'>$x</a> ";
  25. }
  26. if ($currentPage < $pages)
  27. echo "<a href='/my/index.php?page=".($currentPage+1)."'> Next</a>";

Report this snippet 

Comments

RSS Icon Subscribe to comments
Posted By: Tate on July 22, 2008

You need to login to post a comment.