iamandrus
iamandrus

Reputation: 1430

MySQL query only returning one result

I have a query that gets places based on the Haversine algorithm.

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:

$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!

Upvotes: 0

Views: 1662

Answers (2)

Hamid
Hamid

Reputation: 1760

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

Upvotes: 2

Chandresh M
Chandresh M

Reputation: 3828

you need to use mysql_fetch_assoc() function in while loop for that may be.

i.e:
while($location = mysql_fetch_assoc($getlocations));

print_r($location);

thanks.

Upvotes: -1

Related Questions