簡體   English   中英

為什么我無法使用PHP / MySQL和緯度/經度從此查詢中獲取數組?

[英]Why am I not able to get an array from this query using PHP / MySQL and latitude / longitude?

我有兩個表,但是出於這個問題的目的,我只會使用一個表。 我正在使用城市的經度和緯度來查找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 />";
    }

?>

一如既往,任何幫助將不勝感激。 非常感謝你的幫助!

您的查詢看起來很可疑,我想您有一個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;
");

您應該檢查返回值是否有錯誤,這可能也有參考價值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM