Advertisement
Guest User

Untitled

a guest
Jul 29th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.04 KB | None | 0 0
  1. <?php
  2.  
  3. $db_host = "localhost";
  4. $db_user = "";
  5. $db_pass = "";
  6. $db_name = "";
  7.  
  8. try
  9. {
  10. $DB_con = new PDO("mysql:host={$db_host};dbname={$db_name}",$db_user,$db_pass);
  11. $DB_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  12. }
  13. catch(PDOException $exception)
  14. {
  15. echo $exception->getMessage();
  16. }
  17. ?>
  18.  
  19. $limit = (intval($_GET['limit']) != 0) ? $_GET['limit'] : 5;
  20. $offset = (intval($_GET['offset']) != 0) ? $_GET['offset'] : 0;
  21.  
  22. $sql = "SELECT * FROM wuno_inventory WHERE 1 ORDER BY id ASC LIMIT $limit OFFSET $offset";
  23. try {
  24. $stmt = $DB_con->prepare($sql);
  25. $stmt->execute();
  26. $results = $stmt->fetchAll();
  27. }
  28. catch (Exception $ex) {
  29. echo $ex->getMessage();
  30. }
  31. if (count($results) > 0) {
  32. foreach ($results as $res) {
  33. echo '<tr class="invent">';
  34. echo '<td>' . $res['wuno_product'] . '</td>';
  35. echo '<td>' . $res['wuno_alternates'] . '</td>';
  36. echo '<td>' . $res['wuno_description'] . '</td>';
  37. echo '<td>' . $res['wuno_onhand'] . '</td>';
  38. echo '<td>' . $res['wuno_condition'] . '</td>';
  39. echo '</tr>';
  40. }
  41. }
  42. ?>
  43.  
  44. $limit = (intval($_GET['limit']) != 0) ? $_GET['limit'] : 5;
  45. $offset = (intval($_GET['offset']) != 0) ? $_GET['offset'] : 0;
  46.  
  47. $stmt = $DB_con->prepare("SELECT * FROM wuno_inventory WHERE 1 ORDER BY id ASC LIMIT :limit, :offset");
  48. $stmt->bindValue(':limit', (int) trim($_GET['limit']), PDO::PARAM_INT);
  49. $stmt->bindValue(':offset', (int) trim($_GET['offset']), PDO::PARAM_INT);
  50. try {
  51. $stmt->execute();
  52. $results = $stmt->fetchAll();
  53. }
  54. catch (Exception $ex) {
  55. echo $ex->getMessage();
  56. }
  57.  
  58. $stmt->bindParam(':limit', (int) trim($_GET['limit']), PDO::PARAM_INT);
  59. $stmt->bindParam(':offset', (int) trim($_GET['offset']),PDO::PARAM_INT);
  60.  
  61.  
  62.  
  63.  
  64. <script type="text/javascript">
  65. jQuery(document).ready(function($) {
  66. var busy = true;
  67. var limit = 5;
  68. var offset = 0;
  69. var itemID = $("#itemID").val();
  70. var assetPath = "<?php echo $assetPath ?>";
  71. var searchPath = "<?php echo $searchPath ?>";
  72.  
  73. function displayRecords(lim, off) {
  74. jQuery.ajax({
  75. type: "GET",
  76. async: false,
  77. url: assetPath,
  78. data: "limit=" + lim + "&offset=" + off,
  79. cache: false,
  80. beforeSend: function() {
  81. $("#loader_message").html("").hide();
  82. $('#loader_image').show();
  83. },
  84. success: function(html) {
  85. console.log(html);
  86. $("#productResults").append(html);
  87. $('#loader_image').hide();
  88. if (html === null) {
  89. $("#loader_message").html('<button data-atr="nodata" class="btn btn-default" type="button">No more records.</button>').show();
  90. } else {
  91. console.log(html);
  92. $("#loader_message").html('Loading... <img src="../wp-content/uploads/2016/02/loading.gif" alt="Loading" alt="Loading">').show();
  93. }
  94. window.busy = false;
  95. }
  96. });
  97. }
  98.  
  99. (function($) {
  100. $(document).ready(function() {
  101. if (busy === true) {
  102. displayRecords(limit, offset);
  103. busy = false;
  104. }
  105. });
  106. })( jQuery );
  107.  
  108.  
  109.  
  110. (function($) {
  111. $(document).ready(function() {
  112. $(window).scroll(function() {
  113. if ($(window).scrollTop() + $(window).height() > $("#productResults").height() && !busy) {
  114. offset = limit + offset;
  115. displayRecords(limit, offset);
  116.  
  117. }
  118. });
  119. });
  120. })( jQuery );
  121. });
  122. </script>
  123.  
  124. <table id="prods" class="display table center-table" width="100%" >
  125. <thead>
  126. <tr>
  127. <th>Product #</th>
  128. <th>Alternate #</th>
  129. <th>Description</th>
  130. <th>On Hand</th>
  131. <th>Condition</th>
  132. </tr>
  133. </thead>
  134.  
  135. <tbody id="productResults">
  136.  
  137. </tbody>
  138.  
  139. </table>
  140.  
  141. try
  142. {
  143. $DB_con = new PDO("mysql:host={$db_host};dbname={$db_name}",$db_user,$db_pass);
  144. $DB_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  145. }
  146. catch(PDOException $exception)
  147. {
  148. echo $exception->getMessage();
  149. }
  150.  
  151. $limit = (intval($_GET['limit']) != 0) ? (int) $_GET['limit'] : 5;
  152. $offset = (intval($_GET['offset']) != 0) ? (int) $_GET['offset'] : 0;
  153.  
  154.  
  155. try {
  156. $stmt = $DB_con->prepare("SELECT * FROM wuno_inventory LIMIT :limit OFFSET :offset");
  157. $stmt->bindValue(':limit', $limit, PDO::PARAM_INT);
  158. $stmt->bindValue(':offset', $offset, PDO::PARAM_INT);
  159. $stmt->execute();
  160. $results = $stmt->fetchAll();
  161. }
  162. catch (Exception $ex) {
  163. echo $ex->getMessage();
  164. }
  165. if (count($results) > 0) {
  166. foreach ($results as $res) {
  167. echo '<tr class="invent">';
  168. echo '<td>' . $res['wuno_product'] . '</td>';
  169. echo '<td>' . $res['wuno_alternates'] . '</td>';
  170. echo '<td>' . $res['wuno_description'] . '</td>';
  171. echo '<td>' . $res['wuno_onhand'] . '</td>';
  172. echo '<td>' . $res['wuno_condition'] . '</td>';
  173. echo '</tr>';
  174. }
  175. }
  176.  
  177. $offset = (int)trim($offset);
  178. $STH = $DBH->prepare("SELECT * FROM data WHERE 1 LIMIT (:offset), 50");
  179. $STH->bindValue(":offset", (int)$offset, PDO::PARAM_INT);
  180. $STH->execute();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement