0

我想找到附近的位置(php & Mysql),

"SELECT * ,((ACOS(SIN(33.9697897
* PI() / 180) * SIN(`lat` * PI() / 180) + COS(33.9697897
* PI() / 180) * COS(`lat` * PI() / 180) * COS((-118.2468148
-`lon`) * PI() / 180)) * 180 / PI()) * 60 * 1.1515) AS distance FROM `gladlashes` HAVING distance<=150 ORDER BY distance ASC";

当我们直接插入Mysql的sql时,我使用上面的查询它在mysql数据库上运行良好,但是从PHP脚本使用时会出现以下错误,

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* PI() / 180) * SIN(`lat` * PI() / 180) + COS(33.9697897
* PI() / 180) *' at line 1

请帮我

我的 PHP 代码是

<?php
include("db.php");

$ss="SELECT * ,((ACOS(SIN(33.9697897
    * PI() / 180) * SIN(`lat` * PI() / 180) + COS(33.9697897
    * PI() / 180) * COS(`lat` * PI() / 180) * COS((-118.2468148
    -`lon`) * PI() / 180)) * 180 / PI()) * 60 * 1.1515) AS distance FROM `gladlashes` HAVING distance<=150 ORDER BY distance ASC";
     $sql_select=mysql_query($ss,$con) or die(mysql_error());

      while($row=mysql_fetch_array($sql_select))
      {
      $result_data[]=$row;
      }

    echo json_encode(array('posts'=>$result_data));

在 db.php 中仅写入连接

4

1 回答 1

1

出色地...

您没有使用$ss变量来查询数据库。您使用$q1查询字符串查询它...

换行:

$sql_select=mysql_query($ss,$con) or die(mysql_error());
于 2013-09-28T09:34:51.547 回答