Hi
I'm a little stuck... confused, eyes poping out sort of thing... and was wondering if anyone could throw some light on this...
I'm pulling results from my database using a distance from a Lat & Lng, I get the results within the distance fine, my only problem is then sorting the results according to the distance.
As distance is calculated after the query, and not within it, I assume I have to make an array of the results, adding my distance calculation to the results, then sorting on the distance?
so...
The point that we start from
$lat = 52.12345;
$lng = -2.12345;
$set_distance=0.6;
The query to get users near to that point
$result = mysql_query("SELECT * FROM users WHERE (lat > '$lat' - '$set_distance') AND (lat < '$lat' + '$set_distance') AND (lon > '$lon' - '$set_distance') AND (lon < '$lon' + '$set_distance') AND username = '$user' LIMIT 50", $link);
This works fine and returns the results I expect, now I just work out the distance between the start point and the current result in the loop.
while($row=mysql_fetch_array($result)) {
$lat2=$row[lat];
$lon2=$row[lon];
$distance_from_point = getDistanceBetweenPointsNewMiles($lat, $lon, $lat2, $lon2);// returns the distance between the 2 points
mysql_free_result($result);
So I have the results I need, and the distance I need, I just need to display them in the correct ORDER i.e. closest distance first.
I haven't quite mastered arrays yet, and dispite my best efforts am a little stuck! Either that or I just need to go to bed and sleep on it :o