I am trying to sort a mySQL results by distance of site visitor from places listed in the database rows. Should I do the sorting in mySQL and get the sorted results, or retrieve the unsorted results from mySQL database then sort using PHP? Is there a difference i performance?
This is the SQL code I will use if I sort using mySQL.
SELECT ((ACOS(SIN($lat * PI() / 180) * SIN(lat * PI() / 180)
+ COS($lat * PI() / 180) * COS(lat * PI() / 180) * COS(($lon – lon) * PI() / 180)) * 180 / PI()) * 60 * 1.1515)
AS `distance` FROM `members` HAVING `distance`<=’10′ ORDER BY `distance` ASC