MySQL PHP中的排序距离 [英] sorting distance in MySQL PHP
问题描述
Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select
我的代码:
<?php
$Sql="SELECT *, (3959 * acos(cos(radians(37)) * cos(radians(44)) * cos(radians(55) - radians(-122)) + sin(radians(37)) * sin(radians(44))) as distance FROM TableName HAVING distance < 25 ORDER BY distance LIMIT 0 , 20";
$result=mysql_query($Sql);
while ($row = mysql_fetch_array($result)){
echo $row['Id'];
}
错误: 警告:mysql_fetch_array()期望参数1为资源,在/home中给定布尔值...
我在数据库中存储了经度和纬度,我想根据用户当前的经度和纬度以及数据库中存储的商店的经度和纬度来计算KM-距离.我还希望根据距离对结果进行排序.我用谷歌搜索并找到了一些解决方案,但出现了奇怪的错误. 请检查我的代码.我没有在查询中使用变量.我只想测试它是否运行.请帮助
Hi, I have longitude and latitude stored in the database and I want to calculate the KM - distance based on the user's current longitude and latitude with the shop's longitude and latitude stored in database. And I want a sorted result as well based on the distance. I googled and found some solutions but getting weird error.. Please check my code. I am not using variable in query. I just want to test if it runs. Please help
推荐答案
我发现新的应该是这样的
I found new it should be like this
(3959 * acos(cos(radians(37)) * cos(radians(44)) * cos(radians(55) - radians(-122)) + sin(radians(37)) * sin(radians(44))))
您缺少)"
这篇关于MySQL PHP中的排序距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!