0

Here, I'am using this following function: Working in wordpress site.

    function wp_retrieve_information($latitude, $longitude){
    global $wpdb;
    $sql= "SELECT user_email, 
   ( 3959 * acos( cos( radians($latitude) ) * cos( radians( user_lat ) ) 
   * cos( radians(user_long) - radians($longitude)) + sin(radians($latitude)) 
   * sin( radians(user_lat)))) AS distance 
    FROM $wpdb->users 
    having distance < 10";
    $test= $wpdb->get_results($sql) or die(mysql_error());
    //print_r($test);
    foreach ($test as $row) {
    echo $row['user_email'];
    echo $row['distance'];

    }
    return true;
}

Here i'am using $latitude and $longitude as variable in sql query but when I try to call this function website is get totally blank.. may I know where i'am doing the mistake.

1 Answer 1

1

change radians($latitude) to radians(" + $latitude + "), same with the other one

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you for your reply but after trying the above solution, now i'am getting some error i.e You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '133.9667' at line 1
and if i'am using constant value at the place of variables then its working fine.. but i need dynamic values.
echo your sql after constructing it and paste it here
Array ( [0] => stdClass Object ( [user_email] => [email protected] [user_range] => 5 [distance] => 0 ) [1] => stdClass Object ( [user_email] => [email protected] [user_range] => 5 [distance] => 0 ) [2] => stdClass Object ( [user_email] => [email protected] [user_range] => 5 [distance] => 0 ) [3] => stdClass Object ( [user_email] => [email protected] [user_range] => 5 [distance] => 0 ) [4] => stdClass Object ( [user_email] => [email protected] [user_range] => 5 [distance] => 0 ) )
thanks for your effort i got my answer from this link :-stackoverflow.com/questions/21168422/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.