title: mysql select closest lat/long to specific location
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/8604245/nearest-locations-with-latitude-and-longitude">Nearest locations with latitude and longitude</a>  </p>
  </blockquote>
  
  
  
  <p>I have on my db more than 1000 locations (latitude, longitude) and i want to select the 5 nearest one according to a specific location a(lat, long)! can any one give an idea how to do this! i don't want to make the test to calculate all distances between a and other locations this make too much time! </p>
  
  <p>this is what i thought to do but i'm not sure about!!</p>
  
  <pre><code>    $lat = round (48.89463, 3);
      $lng = round (2.33739,2);
  
      $sql=mysql_query("SELECT * 
      FROM tbl z
      WHERE ROUND(z.lat,3) LIKE $lat AND ROUND(z.long,2) LIKE $lng
      LIMIT 0,5") or die(mysql_error());
    while($row=mysql_fetch_assoc($sql))
    {
    echo $row[lat].";".$row[long]."&lt;br&gt;";
    }
  </code></pre>
  
  <p>Thanks! </p>