I have two tables but for the purposes of this question, I will only use one. I am using the latitude and longitude for a city to find airports within 50 miles. As far as I know, it's working but I can't seem to put this into an array with mysql_fetch_array... It's something stupid or something small... it always seems to be one or the other. After trying several things, this is where I am at right now with the code:
<?php
require('dbconnect.php');
//airports Table Columns
//iata_code
//airport_name
//airport_name_clean
//city_id
//airport_lat
//airport_long
$cityLat = "25.788969"; //Miami
$cityLong = "-80.226439"; //Miami
$distance = "10"; //miles?
$airportQuery = mysql_query("select airport_name,
( 3959 * acos( cos( radians($cityLat) )
* cos( radians( locations.lat ) )
* cos( radians( locations.lng ) - radians($cityLong) )
+ sin( radians($cityLat) )
* sin( radians( locations.lat ) ) ) ) AS distance
from airports
and locations.lat between X1 and X2
and locations.Long between y1 and y2
having distance < $distance ORDER BY distance;
");
while($airports = mysql_fetch_array($airportQuery))
{
echo $airports['airport_name'] . "<br />";
}
?>
As always, any help will be greatly appreciated. Thank you so much for your help!