如何解决 PHP 中的 DEGREES?
How can I solve DEGREES in PHP?
当我 运行 使用 PHP 下面的查询时,我收到以下错误:
调用本机函数时参数计数不正确 'DEGREES'
public function getNearbyActivities($lat,$lng)
{
$result = $this->conn->query("SELECT id,name,lat,lng,
ROUND(
111.045 *
DEGREES(
ACOS(
COS(
RADIANS($lat)
)
* COS(
RADIANS(lat)
)
* COS(
RADIANS(lng)
- (
RADIANS($lng)
)
+ SIN(
RADIANS($lat)
)
* SIN(
RADIANS(lat)
)
)
),2)
AS distance_in_km FROM activities
ORDER BY distance_in_km ASC")
or die($this->conn->error);
$stores = array();
while ($activities = $result->fetch_assoc())
$stores[] = $activities;
return $stores;
}
您缺少 )
见下文
$result = $this->conn->query("SELECT id,name,lat,lng,
ROUND(
111.045 *
DEGREES(
ACOS(
COS(
RADIANS($lat)
)
* COS(
RADIANS(lat)
)
* COS(
RADIANS(lng) - (RADIANS($lng)
)
+ SIN(
RADIANS($lat)
)
* SIN(
RADIANS(lat)
)
)
)
) // <- missing brace
,2)
AS distance_in_km FROM activities
ORDER BY distance_in_km ASC")
当我 运行 使用 PHP 下面的查询时,我收到以下错误: 调用本机函数时参数计数不正确 'DEGREES'
public function getNearbyActivities($lat,$lng)
{
$result = $this->conn->query("SELECT id,name,lat,lng,
ROUND(
111.045 *
DEGREES(
ACOS(
COS(
RADIANS($lat)
)
* COS(
RADIANS(lat)
)
* COS(
RADIANS(lng)
- (
RADIANS($lng)
)
+ SIN(
RADIANS($lat)
)
* SIN(
RADIANS(lat)
)
)
),2)
AS distance_in_km FROM activities
ORDER BY distance_in_km ASC")
or die($this->conn->error);
$stores = array();
while ($activities = $result->fetch_assoc())
$stores[] = $activities;
return $stores;
}
您缺少 )
见下文
$result = $this->conn->query("SELECT id,name,lat,lng,
ROUND(
111.045 *
DEGREES(
ACOS(
COS(
RADIANS($lat)
)
* COS(
RADIANS(lat)
)
* COS(
RADIANS(lng) - (RADIANS($lng)
)
+ SIN(
RADIANS($lat)
)
* SIN(
RADIANS(lat)
)
)
)
) // <- missing brace
,2)
AS distance_in_km FROM activities
ORDER BY distance_in_km ASC")