Reputation: 552
I want to find near by locations (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";
I use above query it run fines on mysql database when we directly insert in sql of Mysql, But it gives following error when using from PHP script,
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
Please help me
My Php code is
<?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));
In db.php only connection is writen
Upvotes: 0
Views: 1470
Reputation: 2856
Well...
You're not using your $ss
variable to query the database. You query it using the $q1
query string...
Change the line:
$sql_select=mysql_query($ss,$con) or die(mysql_error());
Upvotes: 1