正如我在标题中提到的,我正在'bid_userloc'表中请求纬度和经度......但我需要结合'wp_usermeta'表中的信息......
SET @centerLat = '48.531157';
SET @centerLng = '-123.782959';
SELECT *, ( 3959 * acos( cos( radians( @centerLat ) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(@centerLng) ) + sin( radians( @centerLat ) ) * sin( radians( lat ) ) ) ) AS distance FROM bid_userloc HAVING distance < 25 ORDER BY distance LIMIT 0 , 20
使用user_id
中的SELECT *
,我需要从wp_userdata
表中获取一些如下所示的用户数据:
id
meta_key
meta_value
例如,我需要meta_value
的{{1}}“昵称”......以及其他一些昵称,但是一旦我看到它是如何完成的,我可以添加更多。< / p>
我真的很感激!
答案 0 :(得分:0)
试试这个,将距离替换为原来的距离,然后用真实的东西替换其他东西:
SET @centerLat = '48.531157';
SET @centerLng = '-123.782959';
SELECT bid_userloc.*, distance, nickname.meta_value, something_else.meta_value
FROM bid_userloc
LEFT JOIN wp_usermeta AS nickname
ON nickname.userid = bid_userloc.user_id
AND nickname.meta_key = 'nickname'
LEFT JOIN wp_usermeta AS something_else
ON something_else.userid = bid_userloc.user_id
AND something_else.meta_key = 'something_else'
HAVING distance < 25
ORDER BY distance
LIMIT 0 , 20
答案 1 :(得分:0)
修改后的答案如下:
SET @centerLat = '48.531157';
SET @centerLng = '-123.782959';
SELECT bid_userloc.*, nickname.meta_value, last_name.meta_value,
( 3959 * acos( cos( radians( @centerLat ) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(@centerLng) ) + sin( radians( @centerLat ) ) * sin( radians( lat ) ) ) ) AS distance
FROM bid_userloc
LEFT JOIN wp_usermeta AS nickname
ON nickname.user_id = bid_userloc.user_id
AND nickname.meta_key = 'nickname'
LEFT JOIN wp_usermeta AS last_name
ON last_name.user_id = bid_userloc.user_id
AND last_name.meta_key = 'last_name'
HAVING distance < 25
LIMIT 0 , 20