Question

I have 2 tables. One with a list of businesses and their addresses the other with a list of zip codes and their longitude and latitude. I have a form that accepts a zip code and a number of miles to check radius.

all the radius stuff works from a script i found online. what I need is to echo the entries of businesses that are within the radius.

So far i have 2 queries. one gets all entries zip codes inside the db the other get all zipcodes within the range i put in the form

i'm using array_intersect to find the matching ones. my problem is it only returns the first entry found. I'm SURE i need a while loop to do this but i have no idea how to do it.

code snippet:

     $insideRadius = array_intersect($data, $zipArray);

The $data is all the zip codes from the business table. the $zip array is all the zip codes within range.

Was it helpful?

Solution

Can't you just select the businesses that have a zipcode listed in the $zipArray?

"SELECT * FROM business WHERE zipcode IN (" . implode(",", $zipArray) . ")"

In PHP you could run it like this:

$result = mysql_query("SELECT * FROM business WHERE zipcode IN (" . implode(",", $zipArray) . ")");
while ($row = mysql_fetch_assoc($result))
{
    echo $row["name"] . "<br />";
    echo $row["zipcode"] . "<br />";
} 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top