loadProduct.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. include('../conn_mysqli.php');
  3. include('../phpMode/rcodeMap.php');
  4. $key = $_GET['key'];
  5. // 设置 $page 的默认值为1,并限定取值范围在1-10之间
  6. $page = isset($_GET['p']) ? max(1, min(10, intval($_GET['p']))) : 1;
  7. // 设置 $limit 的默认值为10,并限定取值范围在1-100之间
  8. $limit = isset($_GET['l']) ? max(1, min(100, intval($_GET['l']))) : 10;
  9. $offset = ($page - 1) * $limit;
  10. // 返回值设定
  11. header('Content-Type:text/json;charset=utf-8;');
  12. $resObj = array(
  13. 'rcode'=>Rcode_OK,
  14. 'data'=>"",
  15. 'msg'=>'ok'
  16. );
  17. if(!isset($_GET['key'])){
  18. $resObj['rcode'] = Rcode_NotParam;
  19. $resObj['data'] = "";
  20. $resObj['msg'] = "key is must set";
  21. echo json_encode($resObj);
  22. exit;
  23. }
  24. $conn = createConn();
  25. $sql = "SELECT p.proid as id,p.remark,p.name,p.image,p.source,p.sourceType FROM mysql85931094_db.hfy_product as p ,mysql85931094_db.hfy_product_type as p_type WHERE p.type_id = p_type.type_id and p_type.type_key = ? limit ?,?";
  26. // 创建stmt
  27. $stmt = mysqli_prepare($conn, $sql);
  28. // 绑定
  29. mysqli_stmt_bind_param($stmt, "sdd",$key, $offset,$limit);
  30. mysqli_stmt_execute($stmt);
  31. $res = mysqli_stmt_get_result($stmt);
  32. while($row = mysqli_fetch_assoc($res)) { $rs[] = $row; }
  33. mysqli_close($conn);
  34. $resObj['data'] = $rs ;
  35. echo json_encode($resObj);
  36. ?>