I am writing a script that locates stores in a 20 mile radius of a given zip code. That part works fine. I am adding the functionality to also choose a product that those stores carry and display only the stores in a 20 mile radius that sell that product.
Each product column in the database has numerous products in it separated by a ';'. I thought I could use the explode function to create an array, but now i am stumped on how to take the array that explode created and add it to the function that finds if the store is within 20 miles of the zip code.
I have tried every operator i could think of (i.e. &&||, &&, ||, and, or) but nothing works.
// Go through and check all stores
while ($row = mysql_fetch_assoc ($result)) {
// Separate closest stores
$distance = Dist ($row['lat'], $row['lon'], $zip['lat'], $zip['lon']);
$preSpecialties = $row['specialties'];
$preDoor=explode (';',$preSpecialties);
$i=count($preDoor);
for($n=0;$n<$i; $n++){
// Check if store is in radius
if ($distance <= $r && $p == ($preDoor[1]) or ($preDoor[2]) ) {
$stores[] = array (
'name' => $row['name'],
'address' => $row['address'],
'state' => $row['state'],
'town' => $row['town'],
'postal' => $row['postal'],
'phone' => $row['phone'],
'hours' => $row['hours'],
'specialties' => $row['specialties']
);
}
}
}
} else {
$Errors = ($Errors) ? $Errors : '<p>Errors were found please try again!</p>';
}
If i change the Products database entry to only have one product I can get it to work by
if ($distance <= $r && $p == $preSpecialties )
Thanks for the help.