Hi all,
I found this query online :
I give it a zip code and radius and it find all zip codes within given radius.
However, I would like to modify this query for if the user searched by city/state and radius instead of zip/radius. the problem is that if there are more than 1 radius's for a city/state then i will have multiple radius's. I have setup a loop from another query to find all different zip codes for a city/state and i get the results in a string.
such as
the question is, can i incorporate multiple zip codes into the top query? I dont get any results when I try this so my logic is obviously wrong.
I want to select all zipcodes,cites,towms... that are within a certain radius to the given zipcode(s) and have it distinct.
Sorry if I am confusing.
Thanks
I found this query online :
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 = '$zipcode' and Z2.ZIPCODE <> '$zipcode' 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
However, I would like to modify this query for if the user searched by city/state and radius instead of zip/radius. the problem is that if there are more than 1 radius's for a city/state then i will have multiple radius's. I have setup a loop from another query to find all different zip codes for a city/state and i get the results in a string.
such as
Code:
while($row=mysql_fetch_array($queryresult)){
$zips1 = $zips1."Z1.ZIPCODE = '".$row['RESTZIP1']."' OR ";
$zips2 = $zips2."Z2.ZIPCODE <> '".$row['RESTZIP1']."' OR ";
}
$zips1 = substr($zips1,0,-4);
$zips2 = substr($zips2,0,-4);
the question is, can i incorporate multiple zip codes into the top query? I dont get any results when I try this so my logic is obviously wrong.
I want to select all zipcodes,cites,towms... that are within a certain radius to the given zipcode(s) and have it distinct.
Sorry if I am confusing.
Thanks