Jump to content

Recommended Posts

Hi i was wanting to know how i can sort my query based on the latitude value for each record minus a base latitude location and perform a secondry sort doing the same thing on the longitude value which should in theory produce the the array sorted by closest records first to the base lat long

 

i have this code below so farbut as i expected i get errors .  I dont know enough about mysql yet too work out how to do what i want

 

 

//
//
$query_accommodation="SELECT * FROM `accomodation` WHERE `lat` > ($hill_lat - 0.2) AND `lat` < ($hill_lat +0.2)AND `long` > ($hill_lon- 0.2) AND `long` < ($hill_lon + 0.2)"ORDER BY (`lat`-$hill_lat) ASC,(`long`-$hill_longitude) ASC ;
//
//

 

where $hill_longitude and $hill_lat are my base lat and long i will be comparing each record in the database too

 

p.s ( if i take out the order by bit this query works fine al be it not sorted)

 

Please help

Thanks

 

Link to comment
https://forums.phpfreaks.com/topic/197796-help-with-mysql-query/
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.