i have a mysql table structured as per the example below:
POSTAL_CODE_ID|PostalCode|City|Province|ProvinceCode|CityType|Latitude|Longitude
7|A0N 2J0|Ramea|Ne
You simply take your haversine formula and apply it like this:
SELECT *,
6371 * ACOS(SIN(RADIANS( $lat1 )) * SIN(RADIANS(`Latitude`)) +
COS(RADIANS( $lat1 )) * COS(RADIANS(`Latitude`)) * COS(RADIANS(`Longitude`) -
RADIANS( $lon1 ))) AS `distance`
FROM `table`
WHERE `distance` <= 20
ORDER BY `distance` ASC
Replace $lat1
and $lon1
with the latitude and longitude you want to compare against.