query('SELECT rowid,* FROM pharmacies');
foreach ($result as $row) {
$distance = $geo->straight_line_distance($Lat, $Lon, $row['Latitude'], $row['Longitude']);
if ($distance < $shortest)
{
$pharmacy = $row['Pharmacy'];
$address = $row['Address'];
$city = $row['City'];
$state = $row['State'];
$zip = $row['Zip'];
$latitude = $row['Latitude'];
$longitude = $row['Longitude'];
$shortest = $distance;
}
}
$db = NULL;
}
catch(PDOException $e)
{
echo 'PDO Exception: ' . $e-> getMessage();
exit;
}
break;
// case 'POST':
// break;
// case 'PUT':
// break;
// case 'DELETE':
// break;
default:
// Invalid Request Method
header("HTTP/1.0 405 Method Not Allowed");
exit;
}
// Output JSON back to HTML file.
echo 'Closest Pharmacy To you is:
';
echo $pharmacy . '
';
echo $address . '
';
echo $city . '
';
echo $state . '
';
echo $zip . '
';
echo '
';
// echo $latitude . '
';
// echo $longitude . '
';
echo 'Distance of - ' . round($shortest, 1) . ' mile(s) away.
';
exit;
// ##### END OF PROGRAM ################################################################################################
/**
* GetParam - Returns the GET or POST values, and allows for defaults if not present.
* @param $param_name
* @param null $default
*
* @return string|null
*/
function GetParam($param_name, $default=NULL)
{
global $_POST;
global $_GET;
$param_value = "";
if(isset($_POST[$param_name]))
$param_value = $_POST[$param_name];
else if(isset($_GET[$param_name]))
$param_value = $_GET[$param_name];
else if($param_value === '')
$param_value = $default;
return $param_value;
}