Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.55 KB | None | 0 0
  1. <?php
  2.  
  3. $sql = "SELECT COUNT(subjectlevelfee.subjectfeeID) as sbid FROM $statement";
  4. $query = mysqli_query($conn, $sql);
  5.  
  6. $row = mysqli_fetch_row($query);
  7. // Here we have the total row count
  8. $rows = $row[0];
  9. // This is the number of results we want displayed per page
  10. $page_rows = 1;
  11. // This tells us the page number of our last page
  12. $last = ceil($rows/$page_rows);
  13. // This makes sure $last cannot be less than 1
  14. if($last < 1){
  15. $last = 1;
  16. }
  17. // Establish the $pagenum variable
  18. $pagenum = 1;
  19. // Get pagenum from URL vars if it is present, else it is = 1
  20. if(isset($_GET['pn'])){
  21. $pagenum = preg_replace('#[^0-9]#', '', $_GET['pn']);
  22. }
  23. // This makes sure the page number isn't below 1, or more than our $last page
  24. if ($pagenum < 1) {
  25. $pagenum = 1;
  26. } else if ($pagenum > $last) {
  27. $pagenum = $last;
  28. }
  29. // This sets the range of rows to query for the chosen $pagenum
  30. $limit = 'LIMIT ' .($pagenum - 1) * $page_rows .',' .$page_rows;
  31. // This is your query again, it is for grabbing just one page worth of rows by applying $limit
  32. $sql = "$statement2 $limit";
  33. $query = mysqli_query($conn, $sql);
  34.  
  35. // This shows the user what page they are on, and the total number of pages
  36. $textline1 = "Subjects (<b>$rows</b>)";
  37. $textline2 = "Page <b>$pagenum</b> of <b>$last</b>";
  38. // Establish the $paginationCtrls variable
  39. $paginationCtrls = '';
  40. // If there is more than 1 page worth of results
  41. if($last != 1){
  42. /* First we check if we are on page one. If we are then we don't need a link to
  43. the previous page or the first page so we do nothing. If we aren't then we
  44. generate links to the first page, and to the previous page. */
  45. if ($pagenum > 1) {
  46. $previous = $pagenum - 1;
  47. $paginationCtrls .= '<a href="'.$_SERVER['PHP_SELF'].'?pn='.$previous.'">Previous</a> &nbsp; &nbsp; ';
  48. // Render clickable number links that should appear on the left of the target page number
  49. for($i = $pagenum-4; $i < $pagenum; $i++){
  50. if($i > 0){
  51. $paginationCtrls .= '<a href="'.$_SERVER['PHP_SELF'].'?pn='.$i.'">'.$i.'</a> &nbsp; ';
  52. }
  53. }
  54. }
  55. // Render the target page number, but without it being a link
  56. $paginationCtrls .= ''.$pagenum.' &nbsp; ';
  57. // Render clickable number links that should appear on the right of the target page number
  58. for($i = $pagenum+1; $i <= $last; $i++){
  59. $paginationCtrls .= '<a href="'.$_SERVER['PHP_SELF'].'?pn='.$i.'">'.$i.'</a> &nbsp; ';
  60. if($i >= $pagenum+4){
  61. break;
  62. }
  63. }
  64. // This does the same as above, only checking if we are on the last page, and then generating the "Next"
  65. if ($pagenum != $last) {
  66. $next = $pagenum + 1;
  67. $paginationCtrls .= ' &nbsp; &nbsp; <a href="'.$_SERVER['PHP_SELF'].'?pn='.$next.'">Next</a> ';
  68. }
  69. }
  70. $list = '';
  71. while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){
  72.  
  73. $ct = $row['cname'];
  74. $lv = $row['lname'];
  75. $sb = $row['sname'];
  76. $fe = $row['fee'];
  77.  
  78.  
  79. $list .= '<tr class="c"><td>'.$ct.'</td><td>'.$lv.'</td><td>'.$sb.'</td><td>'.$fe.'</td></tr>';
  80.  
  81. }
  82. // Close your database connection
  83. mysqli_close($conn);
  84. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement