我想找到附近的地点(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中,只写连接
答案 0 :(得分:1)
嗯...
您没有使用$ss
变量来查询数据库。您使用$q1
查询字符串...
更改行:
$sql_select=mysql_query($ss,$con) or die(mysql_error());