0
$query = sprintf("SELECT user_id, lat, lng, ( 3959 * acos( cos( radians('%s') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS distance FROM bid_latlng HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20",
    mysql_real_escape_string($center_lat),
    mysql_real_escape_string($center_lng),
    mysql_real_escape_string($center_lat),
    mysql_real_escape_string($radius));

我需要做的是使用上面的语句从表中获取user_login列。wp_usersuser_id

wp_users TABLE
id | user_login

我真的不太清楚如何正确JOIN利用第一个语句中的结果来正确使用这两个语句......

4

1 回答 1

0

下面的查询应该为您提供所需的结果:

sprintf("SELECT bid_latlng.user_id,wp_users.user_login, bid_latlng.lat, bid_latlng.lng, 
( 3959 * acos( cos( radians('%s') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS distance 

    FROM bid_latlng JOIN wp_users ON bid_latlng.user_id = wp_users.user_id HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20",
        mysql_real_escape_string($center_lat),
        mysql_real_escape_string($center_lng),
        mysql_real_escape_string($center_lat),
        mysql_real_escape_string($radius));
于 2012-08-28T22:53:45.770 回答