[英]MySQL query only returning one result
I have a query that gets places based on the Haversine algorithm.我有一个基于 Haversine 算法获取位置的查询。
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;
Then I echo it out in a JSON array like this:然后我在 JSON 数组中回显它,如下所示:
$location = mysql_fetch_assoc($getlocations);
return print_r(json_encode($location));
However, it only returns one row when there should be at least two.但是,当应该至少有两行时,它只返回一行。 Anyone know why it might be doing this?
任何人都知道它为什么会这样做? Thanks!
谢谢!
while( $row = mysql_fetch_assoc($getlocations)){
$location[] = $row;
}
return print_r(json_encode($location));
you need to use mysql_fetch_assoc()
function in while loop for that may be.您可能需要在 while 循环中使用
mysql_fetch_assoc()
function 。
i.e:
while($location = mysql_fetch_assoc($getlocations));
print_r($location);
thanks.谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.