query.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. include_once("../../untils/conn.php");
  3. $search_field = isset($_GET['search_field']) ? $_GET['search_field'] : '';
  4. $keyword = isset($_GET['keyword']) ? $_GET['keyword'] : '';
  5. if ($con) {
  6. if ($db) {
  7. // 根据不同的查询类型构建 SQL 查询语句
  8. switch ($search_field) {
  9. case 'channel':
  10. $sql = "SELECT * FROM oder WHERE channel = '$keyword' ORDER BY id DESC";
  11. break;
  12. case 'channel_one':
  13. $sql = "SELECT * FROM oder WHERE channel_one = '$keyword' ORDER BY id DESC";
  14. break;
  15. case 'channel_two':
  16. $sql = "SELECT * FROM oder WHERE channel_two = '$keyword' ORDER BY id DESC";
  17. break;
  18. default:
  19. $sql = "SELECT * FROM oder ORDER BY id DESC";
  20. break;
  21. }
  22. // 获取分页数据
  23. $data = mysqli_query($con, $sql);
  24. $maxrows = mysqli_num_rows($data);
  25. $page_size = 10;
  26. if ($maxrows % $page_size == 0) {
  27. $maxpage = (int)($maxrows / $page_size);
  28. } else {
  29. $maxpage = (int)($maxrows / $page_size) + 1;
  30. }
  31. if (isset($_GET['curpage'])) {
  32. $page = $_GET['curpage'];
  33. } else {
  34. $page = 1;
  35. }
  36. $start = $page_size * ($page - 1);
  37. $get_sql = $sql . " LIMIT $start,$page_size";
  38. $data = mysqli_query($con, $get_sql);
  39. ?>
  40. <!-- 在这里显示查询到的数据 -->
  41. <table>
  42. <thead>
  43. <tr>
  44. <th>订单ID</th>
  45. <th>订单来源</th>
  46. <th>商品名称</th>
  47. <th>姓名</th>
  48. <th>手机号码</th>
  49. </tr>
  50. </thead>
  51. <tbody>
  52. <?php while ($row = mysqli_fetch_array($data)) { ?>
  53. <tr>
  54. <td><?php echo $row['id']; ?></td>
  55. <td><?php echo $row['channel']; ?></td>
  56. <td><?php echo $row['goods']; ?></td>
  57. <td><?php echo $row['name']; ?></td>
  58. <td><?php echo $row['phone']; ?></td>
  59. </tr>
  60. <?php } ?>
  61. </tbody>
  62. </table>
  63. <!-- 分页代码 -->
  64. <div class="pagination">
  65. <?php
  66. echo "共 $maxpage 页&nbsp;&nbsp;";
  67. echo "每页 $page_size 项&nbsp;&nbsp;";
  68. if ($page > 1) {
  69. $prepage = $page - 1;
  70. echo "<a href='?curpage=$prepage'>上一页</a>&nbsp;&nbsp;";
  71. }
  72. if ($page < $maxpage) {
  73. $nextpage = $page + 1;
  74. echo "<a href='?curpage=$nextpage'>下一页</a>&nbsp;&nbsp;";
  75. }
  76. echo "&nbsp;&nbsp;第 $page 页</p>";
  77. ?>
  78. </div>
  79. <?php
  80. }
  81. }
  82. // 安全过滤
  83. function safe_filter($filter)
  84. {
  85. $filter = str_replace("'", "''", $filter);
  86. $filter = str_replace("%", "\%", $filter);
  87. $filter = str_replace("_", "\_", $filter);
  88. $filter = str_replace("=", "", $filter);
  89. $filter = str_replace(" ", "", $filter);
  90. $filter = str_replace("\,", ",", $filter);
  91. $filter = str_replace("\\", "\\\\", $filter);
  92. return $filter;
  93. }
  94. $search_field = safe_filter($search_field);
  95. $keyword = safe_filter($keyword);
  96. ?>