Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用lat lng和多个搜索联接的mysql查询_Php_Mysql - Fatal编程技术网

Php 使用lat lng和多个搜索联接的mysql查询

Php 使用lat lng和多个搜索联接的mysql查询,php,mysql,Php,Mysql,您好,我有一个类似于mysql的查询,它工作正常,但我想检查条件现在分支的位置。visible=1,然后也显示在查询中 SELECT company.name, company.id, company.mobile, company.telephone, IFNULL(fav.status, 'no') AS 'favorite',branchInfo.logo, ((((acos(sin(($lat*pi()/180)) * sin((bran

您好,我有一个类似于mysql的查询,它工作正常,但我想检查条件现在分支的位置。visible=1,然后也显示在查询中

SELECT 
    company.name,
    company.id,
    company.mobile,
    company.telephone,
    IFNULL(fav.status, 'no') AS 'favorite',branchInfo.logo,
    ((((acos(sin(($lat*pi()/180)) * sin((branches.lat*pi()/180))+cos(($lat*pi()/180)) * cos((branches.lat*pi()/180)) * cos((($lng- branches.lng)*pi()/180))))*180/pi())*60*1.1515*1.609344)) AS 'distance',
    branchInfo.telephone,
    branchInfo.id,
    branchInfo.name,
    branches.buffet,
    branches.halal,
    branches.kidsPlayArea,
    branches.liveBand,
    branches.outdoor,
    branches.sheesha,
    branches.valetParking,
    branches.petsAllowed,
    branches.wiFi,
    branches.sportEvents,
    branches.reservationRequired,
    branches.wheelChairAccess,
    branches.acceptCreditCard,
    branches.brunch,
    branchInfo.name,
    branches.street,
    branches.city,
    branches.area,
    branches.lat,
    branches.lng,
    branches.id,
    branches.visible 
FROM branches
LEFT JOIN users branchInfo 
    ON branchInfo.id=branches.branchId 
LEFT JOIN users company 
    ON company.id=branches.companyId
LEFT JOIN favorite_branches fav 
    ON fav.branchId=branches.branchId AND fav.userId=$uId
HAVING distance < 25
选择
公司名称,
company.id,
移动公司,
公司电话,
如果null(fav.status,'no')为“收藏夹”,branchInfo.logo,
(((acos(sin(($lat*pi()/180))*sin($branchs.lat*pi()/180))+cos($lat*pi()/180))*cos($branchs.lat*pi()/180))*cos(($lng-branchs.lng)*pi()/180))*60*1.1515*1.609344))作为“距离”,
电话分机,
branchInfo.id,
branchInfo.name,
小吃,
我是清真的,
Branchs.Kidsplayrea,
Branchs.liveBand,
户外,
希沙先生,
分支机构。代客泊车,
我的头发已经黄了,
wiFi,
体育赛事,
Branchs.reservationRequired,
分支机构、通道,
信用卡,
B.早午餐,
branchInfo.name,
林荫道,
纽约市,
分支机构和区域,
Branchs.lat,
分公司lng,
b.id,
可见的
从分支机构
左连接用户branchInfo
在branchInfo.id=branchs.branchId上
左加入用户公司
在company.id=branchs.companyId上
左连接最喜欢的分支fav
在fav.branchId=branchs.branchId和fav.userId=$uId上
距离小于25的

使用where子句并在其中添加条件:

SELECT 
    company.name,
    company.id,
    company.mobile,
    company.telephone,
    IFNULL(fav.status, 'no') AS 'favorite',branchInfo.logo,
    ((((acos(sin(($lat*pi()/180)) * sin((branches.lat*pi()/180))+cos(($lat*pi()/180)) * cos((branches.lat*pi()/180)) * cos((($lng- branches.lng)*pi()/180))))*180/pi())*60*1.1515*1.609344)) AS 'distance',
    branchInfo.telephone,
    branchInfo.id,
    branchInfo.name,
    branches.buffet,
    branches.halal,
    branches.kidsPlayArea,
    branches.liveBand,
    branches.outdoor,
    branches.sheesha,
    branches.valetParking,
    branches.petsAllowed,
    branches.wiFi,
    branches.sportEvents,
    branches.reservationRequired,
    branches.wheelChairAccess,
    branches.acceptCreditCard,
    branches.brunch,
    branchInfo.name,
    branches.street,
    branches.city,
    branches.area,
    branches.lat,
    branches.lng,
    branches.id,
    branches.visible 
FROM branches
LEFT JOIN users branchInfo 
    ON branchInfo.id=branches.branchId 
LEFT JOIN users company 
    ON company.id=branches.companyId
LEFT JOIN favorite_branches fav 
    ON fav.branchId=branches.branchId AND fav.userId=$uId
WHERE ((((acos(sin(($lat*pi()/180)) * sin((branches.lat*pi()/180))+cos(($lat*pi()/180)) * cos((branches.lat*pi()/180)) * cos((($lng- branches.lng)*pi()/180))))*180/pi())*60*1.1515*1.609344)) < 25 
AND branches.visible = 1
选择
公司名称,
company.id,
移动公司,
公司电话,
如果null(fav.status,'no')为“收藏夹”,branchInfo.logo,
(((acos(sin(($lat*pi()/180))*sin($branchs.lat*pi()/180))+cos($lat*pi()/180))*cos($branchs.lat*pi()/180))*cos(($lng-branchs.lng)*pi()/180))*60*1.1515*1.609344))作为“距离”,
电话分机,
branchInfo.id,
branchInfo.name,
小吃,
我是清真的,
Branchs.Kidsplayrea,
Branchs.liveBand,
户外,
希沙先生,
分支机构。代客泊车,
我的头发已经黄了,
wiFi,
体育赛事,
Branchs.reservationRequired,
分支机构、通道,
信用卡,
B.早午餐,
branchInfo.name,
林荫道,
纽约市,
分支机构和区域,
Branchs.lat,
美国液化天然气公司,
b.id,
可见的
从分支机构
左连接用户branchInfo
在branchInfo.id=branchs.branchId上
左加入用户公司
在company.id=branchs.companyId上
左连接最喜欢的分支fav
在fav.branchId=branchs.branchId和fav.userId=$uId上
其中(((acos(sin(($lat*pi()/180))*sin((branchs.lat*pi()/180))+cos($lat*pi()/180))*cos((branchs.lat*pi()/180))*cos(($lng-branchs.lng)*pi())*180/pi()*60*1.1515*1.609344))<25
和分支。可见=1

你伤了我的眼睛(为什么我弄坏了你的代码,让你的代码读起来是在发布之前要考虑的。我已经编辑了你的帖子,让代码读起来。你试过添加WHERE子句吗?也可以看到,通常使用GROUP子句,如果没有组,使用WHERE子句。好的catch @ Strawberry。我已经更新了答案。请考虑C。搁置你的投票权。