title: large DB site, need help speeding up query
body: <p>There has to be a faster way to get results. This works great in my small DB, but in my large scare one(20 million rows), this process takes forever. I have tried creating an index for both the lat and lon columns, but that did help. Besides hardware upgrades, is there a way I can speed this up?? currently it is taking a set of cord's and comparing them vs every row in the DB. I am limiting the results to 10.</p>
  
  <pre><code>$sql = sprintf("SELECT lat, lon, ( 3959 * acos( cos( radians('%s') ) * cos( radians( lat ) ) * cos(    radians( lon ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS distance FROM $tbl_name HAVING distance &lt; '%s' ORDER BY distance LIMIT $start, $limit",
  
       mysql_real_escape_string($lat),
  
       mysql_real_escape_string($lon),
  
       mysql_real_escape_string($lat),
  
       mysql_real_escape_string($radius));
  
  $result = mysql_query($sql);
  
  
  while($row = @mysql_fetch_assoc($result)) {
  
  echo oresults....
  
  }
  </code></pre>
  
  <p>thanks,
  Brian</p>