SQL语法错误;检查与MySQL服务器版本对应的手册,以获得正确的语法

时间:2013-09-28 06:52:01

标签: php mysql

我想找到附近的地点(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中,只写连接

1 个答案:

答案 0 :(得分:1)

嗯...

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

进行查询

更改行:

$sql_select=mysql_query($ss,$con) or die(mysql_error());