【发布时间】:2012-07-20 22:04:13
【问题描述】:
我的 PHP 文件中有以下 mysql 查询:
$shopID = mysql_real_escape_string($_GET['shop_id']);
$latitudeCenter = mysql_real_escape_string($_GET['lat_center']);
$longtitudeCenter = mysql_real_escape_string($_GET['lng_center']);
$lat_min = $latitudeCenter - 0.045;
$lat_max = $latitudeCenter + 0.045;
$long_min = $longtitudeCenter - (0.045 / cos($latitudeCenter*M_PI/180);
$long_max = $longtitudeCenter + (0.045 / cos($latitudeCenter*M_PI/180);
$sql = "SELECT * FROM shops WHERE shop_id = '$shopID' AND lat >= '$lat_min' AND lat <= '$lat_max' AND lng >= '$long_min' AND lng <= '$long_max'";
由于某种原因,查询没有成功运行。上述查询有效吗? 谢谢
编辑:
$long_min 和 $long_max 计算有问题,因为当它们被注释掉时,它可以正常工作。
这是我尝试转换为 PHP 的代码:
lat_min = lat_center - 0.045;
lat_max = lat_center + 0.045;
long_min = long_center - (0.045 / Math.cos(lat_center*Math.PI/180);
long_max = long_center + (0.045 / Math.cos(lat_center*Math.PI/180);
我的 PHP 出了什么问题?
【问题讨论】:
-
列
lat的数据类型是什么? -
将错误添加到您的问题中会有很大帮助。
echo mysql_error();在你执行mysql_query($sql);之后。 -
请不要将
mysql_*函数用于新代码。它们不再维护,社区已经开始deprecation process。看到red box?相反,您应该了解prepared statements 并使用PDO 或MySQLi。如果您不能决定,this article 将帮助您选择。如果你想学习,here is good PDO tutorial. -
mysql_error() 仍然返回一个空白页
-
你真的有数据可以匹配你的查询吗?