Jump to content

help with mysql query


fraser5002

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

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.