按纬度和经度的SQL查询返回' null'用php

时间:2016-08-05 16:45:48

标签: php mysql latitude-longitude

我试图通过BD中的纬度和经度返回结果。 我有这个脚本。当我执行phpmyadmin

时它工作正常
 SELECT  `loc` . * , (
(
(
ACOS( SIN( ( 4.6665578 * PI( ) /180 ) ) * SIN( (
`latitude_advertiser` * PI( ) /180 ) ) + COS( ( 4.6665578 * PI( ) /180 ) ) * COS( (
`latitude_advertiser` * PI( ) /180 )
) * COS( (
(
- 74.0524521 -  `longitude_advertiser`
) * PI( ) /180 )
)
)
) *180 / PI( )
) *60 * 1.1515
) AS  `distance` 
FROM  `user_profile_`  `loc` 
HAVING  `distance` <1
LIMIT 0 , 30

但是,当我尝试使用php执行类似的过程时,我的查询返回How Empty。

$connect = mysqli_connect('localhost','root','');

$db =  mysqli_select_db($connect, 's2_001') or die ('Erro #1010');


$distance = 10;
$latitude = 4.6665578;
$longitude = -74.0524521;

$sql = "SELECT `loc`.*, (((acos(sin(($latitude*pi()/180)) * sin((`latitude_advertiser`*pi()/180))+cos(($latitude*pi()/180)) * cos((`latitude_advertiser`*pi()/180)) * cos((($longitude - `longitude_advertiser`)*pi()/180))))*180/pi())*60*1.1515) AS `distance` FROM `user_profile_` `loc` HAVING `distance` < 1";

$query = mysqli_query($connect, $sql);


while($row = mysqli_fetch_array($query)){                            

                            echo $row['id'] . '-' . $row['distance'] . '<br>';  


        }


echo mysqli_num_rows($query); // no line here
echo $sql; // test query, working in phpmyadmin

0 个答案:

没有答案