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