searchProduct.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. include('../conn_mysqli.php');
  3. include('../phpMode/rcodeMap.php');
  4. $key = $_POST['key'];
  5. $type = $_POST['type'] ? $_POST['type'] : 'all';
  6. // 设置 $page 的默认值为1,并限定取值范围在1-10之间
  7. $page = isset($_POST['page']) ? max(1, min(10, intval($_POST['page']))) : 1;
  8. // 设置 $limit 的默认值为20,并限定取值范围在1-100之间
  9. $limit = isset($_POST['limit']) ? max(1, min(100, intval($_POST['limit']))) : 20;
  10. $offset = ($page - 1) * $limit;
  11. header('Content-Type:text/json;charset=utf-8;');
  12. try {
  13. $resObj = array(
  14. 'rcode' => Rcode_OK,
  15. 'data' => "",
  16. 'msg' => 'ok'
  17. );
  18. set_time_limit(50);
  19. // echo "param:" . $key . "-" . $type . "-" . $limit . "-" . $offset . " ";
  20. //echo !empty($key)?"T":"F";
  21. // echo $type == "all" ? "T" : "F";
  22. //exit;
  23. $conn = createConn();
  24. $sql = "";
  25. $stmt = null;
  26. //echo "fuck php not conn ?";
  27. if ($type == "all") {
  28. // 无条件全选
  29. if (!empty($key)) {
  30. // echo " \n php is low \n";
  31. $sql = 'SELECT p.proid as id,p.remark,p.name,p.image,p.source,p.sourceType,p_type.type_key
  32. FROM mysql85931094_db.hfy_product as p , mysql85931094_db.hfy_product_type as p_type
  33. where p.type_id = p_type.type_id and p.name like \''.$key.'\' order by p.proid desc limit ?,?';
  34. } else {
  35. // echo " \n fuck php \n";
  36. $sql = 'SELECT p.proid as id,p.remark,p.name,p.image,p.source,p.sourceType,p_type.type_key
  37. FROM mysql85931094_db.hfy_product as p , mysql85931094_db.hfy_product_type as p_type
  38. where p.type_id = p_type.type_id order by p.proid desc limit ?,?';
  39. }
  40. $stmt = mysqli_prepare($conn, $sql);
  41. mysqli_stmt_bind_param($stmt, "dd", $offset, $limit);
  42. } else {
  43. if (!empty($key)) {
  44. // echo " \n fuck php ? \n";
  45. $sql = 'SELECT
  46. p.proid as id,p.remark,p.name,p.image,p.source,p.sourceType,p_type.type_key
  47. FROM mysql85931094_db.hfy_product as p ,
  48. mysql85931094_db.hfy_product_type as p_type
  49. where p.type_id = p_type.type_id and p_type.type_key = ? and p.name like \''.$key.'\' order by p.proid desc limit ?,?';
  50. $stmt = mysqli_prepare($conn, $sql);
  51. mysqli_stmt_bind_param($stmt, "ssdd", $type, $key, $offset, $limit);
  52. } else {
  53. // echo " \n fuck fuck fuck \n";
  54. $sql = 'SELECT
  55. p.proid as id,p.remark,p.name,p.image,p.source,p.sourceType,p_type.type_key
  56. FROM mysql85931094_db.hfy_product as p , mysql85931094_db.hfy_product_type as p_type
  57. where p.type_id = p_type.type_id and p_type.type_key = ? order by p.proid desc limit ?,?';
  58. $stmt = mysqli_prepare($conn, $sql);
  59. mysqli_stmt_bind_param($stmt, "sdd", $type, $offset, $limit);
  60. }
  61. }
  62. // echo "fuck_1";
  63. mysqli_stmt_execute($stmt);
  64. // echo " fuck_2";
  65. $res = mysqli_stmt_get_result($stmt);
  66. // echo " fuck_3";
  67. // echo "fuck ---------------";
  68. // echo $res;
  69. // echo "fuck " ;
  70. while ($row = mysqli_fetch_assoc($res)) {
  71. $rs[] = $row;
  72. }
  73. // echo "???????????????? ";
  74. // echo "???????????????? ".$res;
  75. mysqli_close($conn);
  76. $resObj['data'] = $rs;
  77. // echo "fuck ".$res;
  78. echo json_encode($resObj);
  79. }catch(Exception $e)
  80. {
  81. // echo 'Message: ' .$e->getMessage();
  82. echo 'server Error Message: notFound';
  83. }
  84. ?>