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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.