我正在尝试使用此查询获取结果
$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准备好的陈述的新手,我出错了?
答案 0 :(得分:0)
老兄,替换这一行,你的代码有误:)
$stmt->bind_param("sssssssssss", $lat, $lat, $lat, $long, $userFk, $long, $lat, $long, $lat, $lat, $lat);
答案 1 :(得分:0)
s - for String
d - for double
i - 表示整数
b - for blob
$stmt->bind_param("sssssssssss", $lat, $lat, $lat, $long, $user, $long, $lat, $long, $lat, $lat, $lat);