title: Sort results in mySQL or in PHP array?
body: <p>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?</p>
  
  <p>This is the SQL code I will use if I sort using mySQL.</p>
  
  <pre><code>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`&lt;=’10′ ORDER BY `distance` ASC
  </code></pre>