I got it. Took sql out of the loop and inserted the array values into it as a comma delimited list in the WHERE IN.
Works great!!
PHP Code:
<?php
if (isset($_POST['search'])){
$mile = $_POST['mile'];
$zip = $_POST['zip'];
//sets variable for mile"s" so if resaults are 1 mile, it is not 1 miles.
if ($mile == 1){
$s = "";
}else{
$s = "s";
}
$zips = $z->get_zips_in_range($zip, $mile, _ZIPS_SORT_BY_DISTANCE_ASC, true);
if ($zips === false){ echo 'Please enter a valid 5-digit ZIP code. Check for accuracy and try again.'.$z->last_error;
}else{
echo "<h3>Yoga Groups within $mile mile$s of $zip</h3>";
$zips_temp = (array_keys($zips)); //saves array keys (zip codes) only to new array
$zip_codes = implode(",",$zips_temp);//makes new array into a comma list and passes list to sql
$sql =("SELECT
yogabp_groups.name,
yogabp_groups.slug,
yogabp_groups.description,
yogabp_groups_extra_details.state,
yogabp_groups_extra_details.street_address,
yogabp_groups_extra_details.city,
yogabp_groups_extra_details.group_id
FROM
zip_code
Inner Join yogabp_groups_extra_details ON yogabp_groups_extra_details.area_code = zip_code.zip_code
Inner Join yogabp_groups ON yogabp_groups.id = yogabp_groups_extra_details.group_id
WHERE
zip_code.zip_code IN ($zip_codes)");
$result = mysql_query($sql);
if (mysql_num_rows($result) == 0) {//if no rows found...echo
echo "No Yoga groups found in your area. Please expand your search and try again";
}
while ($row = mysql_fetch_array($result)){
$name = $row['name'];
$state = $row['state'];
$street = $row['street_address'];
$city = $row['city'];
?>
<table cellspacing="5" cellpadding="5" border="1">
<tr>
<td><?php echo $name?></td>
<td><?php echo $state?></td>
<td><?php echo $street ?></td>
<td><?php echo $city?></td>
</tr>
</table>
<?php
}}}}
Bookmarks