Advertisement
Guest User

Untitled

a guest
Oct 1st, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. $userCount = countUsers(); // Count the amount of users
  2.  
  3. $total_page = ceil($userCount / 25);
  4. $current_page = empty($_GET['page']) ? 1 : $_GET['page'];
  5. $previous_page = $current_page - 1;
  6. $next_page = $current_page + 1;
  7.  
  8. $myPrev = "<div id='prevlink'><a href='".$_SERVER['PHP_SELF']."?page=$previous_page'>Previous</a></div>";
  9. $myNext = "<div id='nextlink'><a href='".$_SERVER['PHP_SELF']."?page=$next_page'>Next</a></div>";
  10.  
  11. /* This creates your offset */
  12. if($current_page > 1){
  13. $myOffset = ($current_page - 1) * 25;
  14. }else{
  15. $myOffset = 0;
  16. }
  17.  
  18.  
  19. /* I created a function that fetches all my user data, and add it to an array ($userData),
  20. with $myOffset as an argument to add to my mySQL query */
  21. $userData = fetchAllUsers(25, $myOffset); //Fetch information for all users
  22.  
  23. /* Checking to make sure that the links are needed; last page no next link, first page
  24. no previous link */
  25. if($next_page > $total_page) {
  26. $myNext = "";
  27. }
  28.  
  29. if($previous_page < 1) {
  30. $myPrev = "";
  31. }
  32.  
  33. echo $myPrev . $myNext;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement