gpt4 book ai didi

php - MySQL 准备好的语句无法正常工作

转载 作者:行者123 更新时间:2023-11-29 18:52:58 27 4
gpt4 key购买 nike

我正在尝试使用此查询获取结果

$lat = -14.4428711;
$long = 28.447634;
$userFk = 11;
$stmt = $this->conn->prepare("SELECT p.`id`, p.`storeFk`, p.`name`, p.`price`, p.`quantity`, p.`image`, s.`name` ,(SELECT COUNT(*) FROM tblpromotion WHERE productFk = p.`id`)

as promotional , s.`profilepicture`,3956 * 2 * ASIN(SQRT( POWER(SIN((? - s.latitude)*pi()/180/2),2) +COS(? *pi()/180 )*COS(?*pi()/180) *


POWER(SIN((?-s.longitude)*pi()/180/2),2))) as distance, p.`dateCreated` FROM `tblproduct` p JOIN `tblstore` s ON p.`storeFk` = s.`id` JOIN tblshoppinglist l ON (


l.name LIKE concat('%',p.name,'%') AND l.userFk = ?) WHERE s.longitude between (?-100/cos(radians(?))*69) and (? +100/cos(radians(?



))*69) and s.latitude between (?-(100/69)) and (? +(100 /69)) GROUP BY p.`id` having distance < 100 ORDER BY distance");


$stmt->bind_param("sssssssssss", $lat, $lat, $lat, $long, $user, $long, $lat, $long, $lat, $lat, $lat);
$stmt->execute();
$response["products"] = array();
$stmt->bind_result($id, $storeFk, $name, $price, $quantity, $itemImage, $shopName, $promotional, $shopProfilePic, $distance, $dateCreated);
while($row = $stmt->fetch())
{
$product = array();
$product["id"] = $id;
$product["storeFk"] = $storeFk;
$product["itemName"] = $name;
$product["price"] = $price;
$product["quantity"] = $quantity;
$product["itemImage"] = $itemImage;
$product["shopName"] = $shopName;
$product["promotional"] = $promotional;
$product["shopProfilePic"] = $shopProfilePic;
$product["distance"] = $distance;
$product["dateCreated"] = $dateCreated;
$response["products"][] = $product;

}

但没有得到任何东西,当我用值替换它时,我得到像

这样的结果
SELECT p.`id`, p.`storeFk`, p.`name`, p.`price`, p.`quantity`, p.`image`, s.`name` ,(SELECT COUNT(*) FROM tblpromotion WHERE productFk = p.`id`) as promotional , s.`profilepicture`,3956 * 2 * ASIN(SQRT( POWER(SIN((-14.4428711 - s.latitude)*pi()/180/2),2) +COS(-14.4428711 *pi()/180 )*COS(-14.4428711*pi()/180) *POWER(SIN((28.447634-s.longitude)*pi()/180/2),2))) as distance, p.`dateCreated` FROM `tblproduct` p JOIN `tblstore` s ON p.`storeFk` = s.`id` JOIN tblshoppinglist l ON (l.name LIKE concat('%',p.name,'%') AND l.userFk = 11) WHERE s.longitude between (28.447634-100/cos(radians(-14.4428711))*69) and (28.447634 +100/cos(radians(-14.4428711))*69) and s.latitude between (-14.4428711-(100/69)) and (-14.4428711 +(100 /69)) GROUP BY p.`id` having distance < 100 ORDER BY distance

我是 PHP 准备好的语句的新手,我哪里出错了?

最佳答案

伙计,替换这一行,你的代码有错误:)

$stmt->bind_param("sssssssssss", $lat, $lat, $lat, $long, $userFk, $long, $lat, $long, $lat, $lat, $lat);

关于php - MySQL 准备好的语句无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44296657/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com