Use PHP to write (My)SQL to discover distances:
function great_circle_mysql_formula($place1, $place2) { $la0 = "((pi() / 2) - radians(90 - $place1[0]))"; $la1 = "((pi() / 2) - radians(90 - $place2[0]))"; $lo0 = "radians($place1[1])"; $lo1 = "radians($place2[1])";return "(6378 / 1.609344) * acos( cos($la0) * cos($la1) * cos($lo0 - $lo1) + sin($la0) * sin($la1) )"; }
You could pass in literal numbers for latitude and longitude in place1 and place2, or (more useful) column names, if you happen to have a table with some latitude and longitude data in it. The "(6378 / 1.609344)" is a constant that specifies the value is in miles; remove the "/ 1.609344" if you're into kilometers.
Shamelessly copied from Perl's Math::Trig module.