All,
I’m looking up a zip code and then finding all the other zip codes in a given radius. I’m trying to make a single call to the database so what kind of query should I use? I was thinking about using an OR clause but was wondering if anyone had any better ideas on query optimization for this? I thought about doing something like this but any advice would be appreciated. Thanks
$zipArray = $zipLoc->inradius($_SESSION['pav_event_zip_code'],50);
$total_zips = count($zipArray);
$sql = "Select * from vendor where vendor_zip='$zipArray[0]'";
for($i=1;$i<$total_zips;$i++){
$sql. = "OR vendor_zip='$zipArray[$i]'";
}
You can use an IN statement, although it won’t be faster it’s definitly easier to read:
Make sure you have the column vendor_zip indexed