gpt4 book ai didi

php - MySQL查询只返回一个结果

转载 作者:行者123 更新时间:2023-11-29 14:47:38 24 4
gpt4 key购买 nike

我有一个基于半正弦算法获取地点的查询。

SELECT
id, description, name,
lat, `long`,
( 3959 * acos( cos( radians($lat) ) * cos( radians( lat ) ) * cos( radians( `long` ) - radians($long) ) + sin( radians($lat) ) * sin( radians( lat ) ) ) ) AS distance
FROM
places
HAVING
distance < 10
ORDER BY
distance
LIMIT 0, 20;

然后我在 JSON 数组中回显它,如下所示:

$location = mysql_fetch_assoc($getlocations);
return print_r(json_encode($location));

但是,当至少应该有两行时,它只返回一行。有人知道为什么会这样做吗?谢谢!

最佳答案

while( $row = mysql_fetch_assoc($getlocations)){
$location[] = $row;
}
return print_r(json_encode($location));

关于php - MySQL查询只返回一个结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6578735/

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