title: How to order php results from database by distance
body: <p>I have a database of adverts which are searched and displayed using PHP. A user inputs their postcode during the search and then the query is executed. When the results page is returned to the user it displays the distance the advert item is from their postcode. </p>
  
  <p>What I need to know is how to order the result by distance. I can order the results for price by placing a sort on the query, but because the distance is calculated on the php page and is different for each user I don't know how to order it.</p>
  
  <p>The distance is calculated using grids and Pythagoras theorem. </p>
  
  <p>Not sure what code would be useful. If you want to see any just let me know. </p>
  
  <p>Thanks </p>