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.

akash ujjwal
  • 174
  • 2
  • 14

1 Answers1

1

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

Z .
  • 12,657
  • 1
  • 31
  • 56
  • 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 – akash ujjwal Mar 12 '15 at 19:22
  • and if i'am using constant value at the place of variables then its working fine.. but i need dynamic values. – akash ujjwal Mar 12 '15 at 19:34
  • echo your sql after constructing it and paste it here – Z . Mar 12 '15 at 20:03
  • Array ( [0] => stdClass Object ( [user_email] => test129@gm.gm [user_range] => 5 [distance] => 0 ) [1] => stdClass Object ( [user_email] => test128@gn.gm [user_range] => 5 [distance] => 0 ) [2] => stdClass Object ( [user_email] => test127@gm.gm [user_range] => 5 [distance] => 0 ) [3] => stdClass Object ( [user_email] => test125@gm.gm [user_range] => 5 [distance] => 0 ) [4] => stdClass Object ( [user_email] => test126@gm.gm [user_range] => 5 [distance] => 0 ) ) – akash ujjwal Mar 12 '15 at 20:52
  • thanks for your effort i got my answer from this link :-http://stackoverflow.com/questions/21168422/php-stdclass-object-in-array – akash ujjwal Mar 12 '15 at 21:19