getSolutionPage.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. //echo "param:" . $key . "-" . $type . "-" . $limit . "-" . $offset . " ";
  13. try {
  14. $resObj = array(
  15. 'rcode' => Rcode_OK,
  16. 'data' => "",
  17. 'msg' => 'ok'
  18. );
  19. set_time_limit(50);
  20. $conn = createConn();
  21. $sql = "";
  22. $stmt = null;
  23. //echo "fuck php not conn ?";
  24. if ($type == "all") {
  25. // 无条件全选
  26. if (!empty($key)) {
  27. // echo " \n php is low \n";
  28. $sql = "SELECT count(*) as total FROM mysql85931094_db.hfy_news as news where news.title like '".$key."'";
  29. $stmt = mysqli_prepare($conn, $sql);
  30. mysqli_stmt_bind_param($stmt, "s", $key);
  31. } else {
  32. // echo " \n fuck php \n";
  33. $sql = 'SELECT count(*) as total
  34. FROM mysql85931094_db.hfy_news as news ';
  35. $stmt = mysqli_prepare($conn, $sql);
  36. // mysqli_stmt_bind_param($stmt, "");
  37. }
  38. } else {
  39. if (!empty($key)) {
  40. // echo " \n fuck php ? \n";
  41. $sql = 'SELECT
  42. count(*) as total
  43. FROM mysql85931094_db.hfy_news as news ,
  44. mysql85931094_db.hfy_news_type as n_type
  45. where news.type_id = n_type.type_id and n_type.type_key = ? and news.title like \''.$key.'\' ;';
  46. $stmt = mysqli_prepare($conn, $sql);
  47. mysqli_stmt_bind_param($stmt, "s", $type);
  48. } else {
  49. // echo " \n fuck fuck fuck \n";
  50. $sql = 'SELECT
  51. count(*) as total
  52. FROM mysql85931094_db.hfy_news as news , mysql85931094_db.hfy_news_type as n_type
  53. where news.type_id = n_type.type_id and n_type.type_key = ? ;';
  54. $stmt = mysqli_prepare($conn, $sql);
  55. mysqli_stmt_bind_param($stmt, "s", $type);
  56. }
  57. }
  58. mysqli_stmt_execute($stmt);
  59. // echo " fuck_2";
  60. $res = mysqli_stmt_get_result($stmt);
  61. // mysqli_stmt_get_result
  62. // $rs = mysqli_fetch_assoc($res);
  63. // 获取行数据
  64. // $result = mysqli_stmt_get_result($stmt);
  65. // $row = mysqli_fetch_array($result, MYSQLI_NUM);
  66. // 获取行数
  67. // $count = $row[0];
  68. $row = mysqli_fetch_array($res, MYSQLI_NUM);
  69. mysqli_close($conn);
  70. $resObj['data'] = array(
  71. 'count' => $row[0],
  72. 'limit' => $limit
  73. );
  74. // echo "fuck ".$res;
  75. echo json_encode($resObj);
  76. }catch(Exception $e)
  77. {
  78. echo 'server Error Message: notFound';
  79. }