| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- include('../conn_mysqli.php');
- include('../phpMode/rcodeMap.php');
- $key = $_POST['key'];
- $type = $_POST['type'] ? $_POST['type'] : 'all';
- // 设置 $page 的默认值为1,并限定取值范围在1-10之间
- $page = isset($_POST['page']) ? max(1, min(10, intval($_POST['page']))) : 1;
- // 设置 $limit 的默认值为20,并限定取值范围在1-100之间
- $limit = isset($_POST['limit']) ? max(1, min(100, intval($_POST['limit']))) : 20;
- $offset = ($page - 1) * $limit;
- header('Content-Type:text/json;charset=utf-8;');
- //echo "param:" . $key . "-" . $type . "-" . $limit . "-" . $offset . " ";
- try {
- $resObj = array(
- 'rcode' => Rcode_OK,
- 'data' => "",
- 'msg' => 'ok'
- );
- set_time_limit(50);
- $conn = createConn();
- $sql = "";
- $stmt = null;
- //echo "fuck php not conn ?";
- if ($type == "all") {
- // 无条件全选
- if (!empty($key)) {
- // echo " \n php is low \n";
- $sql = "SELECT count(*) as total FROM mysql85931094_db.hfy_product as p where p.name like '".$key."'";
- $stmt = mysqli_prepare($conn, $sql);
- mysqli_stmt_bind_param($stmt, "s", $key);
- } else {
- // echo " \n fuck php \n";
- $sql = 'SELECT count(*) as total
- FROM mysql85931094_db.hfy_product as p ';
- $stmt = mysqli_prepare($conn, $sql);
- // mysqli_stmt_bind_param($stmt, "");
- }
- } else {
- if (!empty($key)) {
- // echo " \n fuck php ? \n";
- $sql = 'SELECT
- count(*) as total
- 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 = ? and p.name like \''.$key.'\' ;';
- $stmt = mysqli_prepare($conn, $sql);
- mysqli_stmt_bind_param($stmt, "s", $type);
- } else {
- // echo " \n fuck fuck fuck \n";
- $sql = 'SELECT
- count(*) as total
- 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 = ? ;';
- $stmt = mysqli_prepare($conn, $sql);
- mysqli_stmt_bind_param($stmt, "s", $type);
- }
- }
- mysqli_stmt_execute($stmt);
- // echo " fuck_2";
- $res = mysqli_stmt_get_result($stmt);
- // mysqli_stmt_get_result
- // $rs = mysqli_fetch_assoc($res);
- // 获取行数据
- // $result = mysqli_stmt_get_result($stmt);
- // $row = mysqli_fetch_array($result, MYSQLI_NUM);
- // 获取行数
- // $count = $row[0];
- $row = mysqli_fetch_array($res, MYSQLI_NUM);
- mysqli_close($conn);
- $resObj['data'] = array(
- 'count' => $row[0],
- 'limit' => $limit
- );
- // echo "fuck ".$res;
- echo json_encode($resObj);
- }catch(Exception $e)
- {
- echo 'server Error Message: notFound';
- }
|