/ Published in: PHP
Expects databaseTable to have both lat and lon columns with appropriate location coordinate data.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
$HelpQuery = sprintf("SELECT *, ( 3959 * acos( cos( radians( %s ) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians( %s ) ) + sin( radians( %s ) ) * sin( radians( lat ) ) ) ) AS distance FROM databaseTable ORDER BY distance LIMIT 0,5",$lat,$lng,$lat); $result['info'] = ""; if($HelpResult) { { $result['info'][] = $Helprow; } } else { $result['info'] = "Error"; }