reslts in miles
SELECT id, ( 3959 * acos( cos( radians(YOUR_LATITUDE) ) * cos( radians( YOUR_DB_LAT_FIELD ) ) * cos( radians( YOUR_DB_LNG_FIELD )
- radians(YOUR_LONGITUDE) ) + sin( radians(YOUR_LATITUDE) ) * sin( radians( YOUR_DB_LAT_FIELD ) ) ) ) AS distance
FROM YOUR_DB_TABLE HAVING distance < 25 ORDER BY distance ASC;
YOUR_LATITUDE and YOUR_LONGITUDE are where you enter the values of your ZIP code, YOUR_DB_LAT_FIELD and YOUR_DB_LNG_FIELD are the fields containing the longitude and latitude values for each ZIP code in your database, and finally YOUR_DB_TABLE is the database table you are querying. “distance < 25″ tells the database to only return values that are less than 25 miles away. You can modify or omit this to return all.