Well, I don't think asking mySQL to do the calculation is a wise way. Definitely it will cause time out. It might be true that mySQL may have a compiled calculating module which runs faster. But it is more important that mySQL needs to calculate every single row before returning u the result. This is unnecessary.
The trick you can play is like this:
The longtitude and latitude stored in database is some sorts of angular measurement, be degree or radient. Either way, you can translate it to linear distance.
Take this example as a illustration. Don't comment on the numerical value as I don't have real data. The order of magnitude is wrong as well. But I'm sure u know what I'm saying.
Let your location be at (5.0 North, 15.0 East)
Let earth radius be 1000 km (for ez cal)
Say you want to find all records within 1Km radius,
To begin, 1000km radius translates to 0.001 radiant corresponds to 1 Km distance on earth surface.
So your target will be limited in the square area between (4.999 North to 5.001 North, S-N directoin) and (14.999 East and 15.001 East E-W direction)
Than make your SQL to select only postal points within this area:
$query2k = "SELECT city, state, zipcode, latitude, longitude FROM zipcodes where (longtitude is between 14.999 and 15.001) and (latitude is between 4.999 and 5.001)"
[The WHERE clause is only pseudo code, finetune the syntax please]
This will return you a finite subset of locations. Then invoke php function to loop through the recordset to eliminate addresses inside the square but outside the embedded circle.
Try this. It should work.
But please, be kindly post back the result. Just interest to know.
Fred