Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adjust search query for multiple entries

Status
Not open for further replies.

justride

Programmer
Jan 9, 2004
251
US
Hi all,

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
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

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top