MySQL PHP中的排序距离 [英] sorting distance in MySQL PHP

查看:99
本文介绍了MySQL PHP中的排序距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
mysql_fetch_array()期望参数1成为资源,在select中给出布尔值

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆