Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1. <div id="load_data">
  2.  
  3. </div>
  4.  
  5. $(document).ready(function(){
  6.  
  7. load_data();
  8.  
  9. function load_data(page){
  10.  
  11. $('#load_data').html('<div id="status" style="" ></div>');
  12. var action = 'pagination2';
  13. $.ajax({
  14. url:"pagination2.php?="+page,
  15. method:"GET",
  16. error: function(xhr, text){
  17. alert("Whoops! The request for new content failed");
  18. },
  19. data:{page:page},
  20. success:function(data){
  21. $('#load_data').html(data);
  22. $('.pagination_link').html(data.pagination_link);
  23. },
  24. })
  25. }
  26.  
  27. $(document).on('click', '.pagination_link', function(event) // this line binds the handler to your pagination
  28. {
  29. event.preventDefault(); //this prevents the link being loaded as a new page, the default behaviour
  30. var page = $(this).attr("id"); //we get the url of the page to load in by ajax
  31. load_data(page);
  32. //history.pushState(null, null, $(this).attr('id'));
  33. //historyedited = true;
  34. });
  35. });
  36. </script>
  37.  
  38. <?php require_once('../private/initialize.php'); ?>
  39.  
  40. <?php
  41. $page = '';
  42.  
  43. $rowperpage = 10;
  44.  
  45. $page = $_GET['page'] ?? 1;
  46.  
  47. //$page = !empty($_GET['page']) ? (int)$_GET['page'] : '1';
  48.  
  49. $page = $page - 1;
  50.  
  51. $p = $page * $rowperpage;
  52.  
  53. ?>
  54.  
  55. <?php
  56. $visible = $visible ?? true;
  57.  
  58. $id = isset($_GET['id']) ? $_GET['id'] : '1';
  59.  
  60. $products_count = count_all_products(['visible' => $visible]);
  61.  
  62. $sql = "SELECT * FROM products ";
  63. $sql .= "WHERE visible = true ";
  64. $sql .= "ORDER BY position ASC ";
  65. $sql .= "LIMIT ".$p.", ".$rowperpage."";
  66.  
  67. $product_set = find_by_sql($sql);
  68.  
  69. $product_count = mysqli_num_rows($product_set);
  70.  
  71. if($product_count == 0) {
  72. echo "<h1>no products</h1>";
  73. }
  74.  
  75. while($run_product_set = mysqli_fetch_assoc($product_set)) { ?>
  76.  
  77. <div style="float: left; margin-left: 20px; margin-top: 10px; class="small">
  78.  
  79. <a href="<?php echo url_for('/show.php?id=' . h(u($run_product_set['id']))); ?>">
  80. <img src="staff/images/<?php echo h($run_product_set['filename']); ?> " width="150">
  81. </a>
  82.  
  83. <p><?php echo h($run_product_set['prod_name']); ?></p>
  84.  
  85. </div>
  86.  
  87. <?php }
  88.  
  89. mysqli_free_result($product_set);
  90.  
  91. ?>
  92. <section class="pagination">
  93.  
  94. <?php
  95.  
  96. $url = url_for('index_all.php');
  97.  
  98. $page_nb = isset($_GET['page']) ? $_GET['page'] : '1';
  99. $check = $p + $rowperpage;
  100. $prev_page = $page_nb - 1;
  101.  
  102. $limit = $products_count / $rowperpage;
  103. //echo $limit;
  104. //exit;
  105. $limit = ceil($limit);
  106. $current_page = $page_nb;
  107.  
  108. if($page_nb > 1) {
  109. //echo "<a href='index_all.php?page=".$prev_page."'>Back</a>";
  110. echo "<span class='pagination_link' style='cursor:pointer;' id='".$prev_page."'>Back</span>";
  111.  
  112. }
  113.  
  114. if ( $products_count > $check ) {
  115.  
  116. for ( $i = max( 1, $page_nb - 5 ); $i <= min( $page_nb + 5, $limit ); $i++ ) {
  117. if ( $current_page == $i ) {
  118. echo "<span class="selected">{$i}</span>";
  119. } else {
  120. //echo "<a href="{$url}?page=" . $i . "">{$i}</a>";
  121. //echo "<span class='pagination_link' style='cursor:pointer;' id='".$i."' onclick='window.history.go(1); return false;'>".$i."</span>";
  122. echo "<span class='pagination_link' style='cursor:pointer;' id='".$i."'>".$i."</span>";
  123. }
  124. }
  125. }
  126.  
  127.  
  128.  
  129. if ($products_count > $check) {
  130.  
  131. $next_page = $page_nb + 1;
  132. //echo "<a href='index_all.php?page=".$next_page."'>Next</a>";
  133. echo "<span class='pagination_link' style='cursor:pointer;' id='".$next_page."'>Next</span>";
  134.  
  135. }
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142. ?>
  143.  
  144. </section>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement