I have a db of zip codes, towns, states lats and longs...
can i build a dynamci query that takes a zip code and only pulls out records that are within a certain criteria?
I found this code online, it is somewhat straighforward.
somehow incorporate the computation in the query so i dont have to do the checking a php through a while loop or something.
thanks
chris
can i build a dynamci query that takes a zip code and only pulls out records that are within a certain criteria?
Code:
$db = new My_DB("SELECT *
FROM airports AS a
WHERE id IN ('$origin', '$destination')");
$db->next_record();
$a = deg2rad($db->f('latitude'));
$b = deg2rad($db->f('longitude'));
$origin_id = $db->f('id');
$origin_name = $db->f('name');
$db->next_record();
$c = deg2rad($db->f('latitude'));
$d = deg2rad($db->f('longitude'));
$destinati
$destinati
$r=3963.1; //radius of the earth in miles
//calculate the distance between the two points
$distance = acos(
(cos($a) * cos($b) * cos($c) * cos($d)) +
(cos($a) * sin($b) * cos($c) * sin($d)) +
(sin($a) * sin($c))
) * $r;
if($origin == $destination) {
echo "Distance = 0
";
} else {
echo "Origin: ($origin_id) $origin_name
";
echo "Destination: ($destination_id) $destination_name
";
echo "Distance in miles: ", round($distance,4), "
";
echo "Distance in kilometers: ", round(($distance*1.609),4), "
";
}
somehow incorporate the computation in the query so i dont have to do the checking a php through a while loop or something.
thanks
chris