title: Find closest 10 cities with MySQL using latitude and longitude?
body: <p>I have searched the Web a lot to find the solution for my problem but I still can't figure it out. </p>
  
  <p>I have a very simple database with id, city name, latitude, longitude and city_info. When someone enters a city page a would like to show the 10 nearby cities. </p>
  
  <p>How can I calculate this with MySQL and return it with PHP?</p>
  
  <p>I have seen a lot of suggestions on this website, however none of these work somehow.</p>
  
  <p>What I tried without success. I do not get any results.</p>
  
  <pre><code>&lt;?php
  $slatitude = 43.2141341;
  $slongitude = 64.4368684;
  $miles = 200;
  
  //connect
  
  $query = "SELECT *, 
  ( 3959 * acos( cos( radians('$slatitude') ) * 
  cos( radians( latitude ) ) * 
  cos( radians( longitude ) - 
  radians('$slongitude') ) + 
  sin( radians('$slatitude') ) * 
  sin( radians( latitude ) ) ) ) 
  AS distance FROM cities HAVING distance &lt; '$miles' ORDER BY distance ASC LIMIT 0, 10";
  
  $query = mysql_query($query);
  $numrows = mysql_num_rows($query);
  if ($numrows &gt; 0){
  
  while ($row = mysql_fetch_assoc($query)){
  $id = $row['id'];
  $cityname = $row['cityname'];
  $latitude = $row['latitude'];
  $longitude = $row['longitude'];
  
  echo "$cityname&lt;br /&gt;";
  
  }}
  
  ?&gt;`
  </code></pre>