Does anybody have time helping me out? I have a query that calculates the distance between a given zip code and all other zipcodes in the db within a specified search radius. It works fine.
however if a user wants to search for Boston, MA within 20 miles i have a problem. We all know there are more than 1 zip code for soem cities, so i need to run this query multiple times and merge all the records found. The way I am doing it now is very inneficient and take way to much computation time.
I would like to nest it in the query soemhow where my calculation can calculate a number of times.
heres the current query that works for 1 zip code:
instead of using zips[$i] I want to have a string of zip codes. I just cant figure this out in mysql.
Thanks
however if a user wants to search for Boston, MA within 20 miles i have a problem. We all know there are more than 1 zip code for soem cities, so i need to run this query multiple times and merge all the records found. The way I am doing it now is very inneficient and take way to much computation time.
I would like to nest it in the query soemhow where my calculation can calculate a number of times.
heres the current query that works for 1 zip code:
Code:
"SELECT Z2.TOWN,Z2.STATE,Z2.ZIPCODE,
TRUNCATE (acos( (sin( Z1.LATITUDE * 0.017453293 ) * sin( Z2.LATITUDE * 0.017453293 ) ) + (cos( Z1.LATITUDE * 0.017453293 ) * cos( Z2.LATITUDE * 0.017453293 ) * cos( (Z2.LONGITUDE * 0.017453293) - ( Z1.LONGITUDE * 0.017453293 ) ) )) *3956,1) AS DISTANCE
FROM DINEZIPCODES Z1,DINEZIPCODES Z2
WHERE Z1.ZIPCODE = '$zips[$i]' AND acos( (sin( Z1.LATITUDE * 0.017453293 ) * sin( Z2.LATITUDE * 0.017453293 ) ) + (cos( Z1.LATITUDE * 0.017453293 ) * cos( Z2.LATITUDE * 0.017453293 ) * cos( (Z2.LONGITUDE * 0.017453293) - ( Z1.LONGITUDE * 0.017453293 ) ) )) *3956
BETWEEN 0 AND '$radius'
ORDER BY DISTANCE DESC";
instead of using zips[$i] I want to have a string of zip codes. I just cant figure this out in mysql.
Thanks