我有两张桌子但是出于这个问题的目的,我只会使用一张桌子。我正在使用纬度和经度来查找50英里范围内的城市。据我所知,它正在工作,但我似乎无法将它放入一个带有mysql_fetch_array的数组中......这是一些愚蠢或小的东西......它似乎总是一个或另一个。在尝试了几件事后,这就是我现在所处的代码:
<?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 />";
}
?>
与往常一样,任何帮助将不胜感激。非常感谢你的帮助!
答案 0 :(得分:0)
您的查询看起来很可疑,我认为您应该and
时有一个where
:
$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
WHERE locations.lat between X1 and X2
and locations.Long between y1 and y2
having distance < $distance ORDER BY distance;
");
您应该检查错误的返回值,这也可能是提供信息的。