Jump to content

query problem


smith.james0

Recommended Posts

I am having a problem with the following code it should return results within 100 in distance order, but it's returning results within 100 miles but not in distance order.

 

$code2_lat 53.447088 $code2_long -2.541988

 

$sqlz = "SELECT *, ((ACOS(SIN($code2_lat * PI() / 180) * SIN(lat * PI() / 180) + COS($code2_lat * PI() / 180) * COS(lat * PI() / 180) * COS(($code2_long - lon) * PI() / 180)) * 180 / PI()) * 60 * 1.1515) AS `distance` FROM `table` HAVING `distance`<='100' ORDER BY 'distance' ASC";

 

example of lat and long from the table

1) 53.294122 -0.340749

2) 53.347162 -2.609342

 

the query is returning 1 before 2 when it should be the other way round

 

Can anyone see whats wrong?

 

James

Link to comment
https://forums.phpfreaks.com/topic/272939-query-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.