loadSolution.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. $parentSolutionType = 1;
  11. // 返回值设定
  12. header('Content-Type:text/json;charset=utf-8;');
  13. $resObj = array(
  14. 'rcode'=>Rcode_OK,
  15. 'data'=>"",
  16. 'msg'=>'ok'
  17. );
  18. if(!isset($_GET['key'])){
  19. $resObj['rcode'] = Rcode_NotParam;
  20. $resObj['data'] = "";
  21. $resObj['msg'] = "key is must set";
  22. echo json_encode($resObj);
  23. exit;
  24. }
  25. $conn = createConn();
  26. $sql = "SELECT news.id,news.remark,news.title as name,news.image,news.source_val as source,news.sourceType
  27. FROM mysql85931094_db.hfy_news as news ,mysql85931094_db.hfy_news_type as n_type
  28. WHERE news.type_id = n_type.type_id and n_type.parent_type = ? and n_type.type_key = ? limit ?,?";
  29. // 创建stmt
  30. $stmt = mysqli_prepare($conn, $sql);
  31. // 绑定
  32. mysqli_stmt_bind_param($stmt, "dsdd",$parentSolutionType,$key, $offset,$limit);
  33. mysqli_stmt_execute($stmt);
  34. $res = mysqli_stmt_get_result($stmt);
  35. while($row = mysqli_fetch_assoc($res)) { $rs[] = $row; }
  36. mysqli_close($conn);
  37. $resObj['data'] = $rs ;
  38. echo json_encode($resObj);
  39. ?>