I have a SELECT SQL statement that returns a Latitude, Longitude and Distance as result (using the Haversine formula). Now I need to store these values as variables within the PHP script as I need to do further processing on the results. Can anyone tell me how I can do this?
Here is my SQL Statement
UPDATED
$query = $db->prepare("SELECT `Latitude`, `Longitude`, (6378160 * acos( cos( radians(:latitude) ) * cos( radians( Latitude ) ) * cos( radians( Longitude ) - radians(:longitude) ) + sin( radians(:latitude) ) * sin( radians( Latitude ) ) ) ) AS distance FROM `mytable` HAVING distance < :radius ORDER BY distance;");
// Assign parameters
$query->bindParam(':latitude',$newLatitude);
$query->bindParam(':longitude',$newLongitude);
$query->bindParam(':radius',$radius);
//Execute query
$query->execute();
$q = $db->query($query);
$q->setFetchMode(PDO::FETCH_ASSOC);
// fetch
while($r = $q->fetch()){
$eLatitude = $r->Latitude;
$eLongitude = $r>Longitude;
$distance = $r->Distance;
}
I updated my php code above. Is this code's syntax correct? Or the way I'm doing it is all wrong?