Advertisement
Guest User

Untitled

a guest
Sep 12th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.39 KB | None | 0 0
  1.  
  2.  
  3. <?php
  4. function perpage($count, $per_page = '10',$href) {
  5. $output = '';
  6. $paging_id = "link_perpage_box";
  7. if(!isset($_POST["page"])) $_POST["page"] = 1;
  8. if($per_page != 0)
  9. $pages = ceil($count/$per_page);
  10. if($pages>1) {
  11.  
  12. if(($_POST["page"]-3)>0) {
  13. if($_POST["page"] == 1)
  14. $output = $output . '<span id=1 class="current-page">1</span>';
  15. else
  16. $output = $output . '<input type="submit" name="page" class="perpage-link" value="1" />';
  17. }
  18. if(($_POST["page"]-3)>1) {
  19. $output = $output . '...';
  20. }
  21.  
  22. for($i=($_POST["page"]-2); $i<=($_POST["page"]+2); $i++) {
  23. if($i<1) continue;
  24. if($i>$pages) break;
  25. if($_POST["page"] == $i)
  26. $output = $output . '<span id='.$i.' class="current-page" >'.$i.'</span>';
  27. else
  28. $output = $output . '<input type="submit" name="page" class="perpage-link" value="' . $i . '" />';
  29. }
  30.  
  31. if(($pages-($_POST["page"]+2))>1) {
  32. $output = $output . '...';
  33. }
  34. if(($pages-($_POST["page"]+2))>0) {
  35. if($_POST["page"] == $pages)
  36. $output = $output . '<span id=' . ($pages) .' class="current-page">' . ($pages) .'</span>';
  37. else
  38. $output = $output . '<input type="submit" name="page" class="perpage-link" value="' . $pages . '" />';
  39. }
  40.  
  41. }
  42. return $output;
  43. }
  44.  
  45. function showperpage($sql, $per_page = 10, $href) {
  46. $result = mysql_query($sql);
  47. $count = mysql_num_rows($result);
  48. $perpage = perpage($count, $per_page,$href);
  49. return $perpage;
  50. }
  51. ?>
  52. <div class="wrap">
  53. <div id="primary" class="content-area">
  54. <main id="main" class="site-main" role="main">
  55. <form name="frmSearch" method="post" action="">
  56. <div class="search-box">
  57. <p><input type="text" placeholder="Batch No" name="search[batch_no]" class="demoInputBox" value="<?php echo $batch_no; ?>" />
  58. <br/>
  59. <input type="text" placeholder="RFID Chip No" name="search[rfid_chip_no]" class="demoInputBox" value="<?php echo $rfid_chip_no; ?>" />
  60. <input type="submit" name="go" class="btnSearch" value="Search">
  61. <input type="reset" class="btnSearch" value="Reset" onclick="window.location=''"></p>
  62. </div>
  63. </form>
  64.  
  65. <h2>Search Result</h2>
  66.  
  67. <?php
  68.  
  69. $category = "";
  70. $code = "";
  71.  
  72. $queryCondition = "";
  73. if(!empty($_POST["search"])) {
  74. foreach($_POST["search"] as $k=>$v){
  75. if(!empty($v)) {
  76.  
  77. $queryCases = array("category","code");
  78. if(in_array($k,$queryCases)) {
  79. if(!empty($queryCondition)) {
  80. $queryCondition .= " AND ";
  81. } else {
  82. $queryCondition .= " WHERE ";
  83. }
  84. }
  85. switch($k) {
  86. case "category":
  87. $category = $v;
  88. $queryCondition .= "category LIKE '" . $v . "%'";
  89. break;
  90. case "code":
  91. $code = $v;
  92. $queryCondition .= "code LIKE '" . $v . "%'";
  93. break;
  94. }
  95. }
  96. }
  97. }
  98. $orderby = " ORDER BY id desc";
  99. $sql = "SELECT * FROM toy " . $queryCondition;
  100. $href = 'index.php';
  101.  
  102. $perPage = 2;
  103. $page = 1;
  104. if(isset($_POST['page'])){
  105. $page = $_POST['page'];
  106. }
  107. $start = ($page-1)*$perPage;
  108. if($start < 0) $start = 0;
  109.  
  110. $query = $sql . $orderby . " limit " . $start . "," . $perPage;
  111. $result = $db_handle->runQuery($query);
  112.  
  113. if(!empty($result)) {
  114. $result["perpage"] = showperpage($sql, $perPage, $href);
  115. }
  116. ?>
  117. <html>
  118.  
  119. <head>
  120. <title>Search Result</title>
  121. </head><?php
  122. if (empty($result)) {
  123. echo "<p>No results matched. Please try again..</p>\n";
  124. } else {
  125. ?>
  126.  
  127. <table cellpadding="10" cellspacing="1">
  128. <?php
  129. foreach($result as $k=>$v) {
  130. if(is_numeric($k)) {
  131. ?>
  132. <thead>
  133. <tr>
  134. <th><strong>Name</strong></th>
  135. <td><?php echo $result[$k]["name"]; ?></td>
  136. </tr>
  137. <tr>
  138. <th><strong>Code</strong></th>
  139. <td><?php echo $result[$k]["code"]; ?></td>
  140. </tr>
  141. <tr>
  142. <th><strong>Category</strong></th>
  143. <td><?php echo $result[$k]["category"]; ?></td>
  144. </tr>
  145. </thead>
  146. <tbody>
  147.  
  148. <tr>
  149.  
  150.  
  151. <?php
  152. }
  153. }
  154. if(isset($result["perpage"])) {
  155. ?>
  156. <tr>
  157. <td colspan="6" align=right> <?php echo $result["perpage"]; ?></td>
  158. </tr>
  159. <?php }
  160. }?>
  161. <tbody>
  162. </table>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement