Again, I apologize if I'm overlooking something in the above posts, but the problem is that the above suggestions do not sort on the distance ($zip array's $value). Instead, they seem to focus on sorting the actual zip codes, which is irrelevant.
Here is another attempt at clarifying the problem...
// TEST WITH SEATTLE ZIP
$zipCode_searched = '98104';
$zipCode_distance += 10;
$z = new zipcode_class;
$zips = $z->get_zips_in_range($zipCode_us, $zipCode_distance);
foreach ($zips as $key => $value) {
echo "zips[$key] = $value<br />\n";
}
The above array returns the following data for nearby zip codes and their distance from 98104...
zips[98012] = 5.82
zips[98014] = 17.09
zips[98019] = 15.39
zips[98020] = 5.85
zips[98021] = 3.6
zips[98023] = 1.09
There is no problem selecting all the nearby dealers in my database using this query...
$sql = "SELECT * FROM dealerAmerica ";
$sql .= "WHERE zipCode = '$zipCode_us' ";
foreach ($zips as $key => $value) {
$sql .= "OR zipCode = '$key' ";
}
$sql .= " AND disabled != '1'";
//$sql .= " ORDER BY zipCode, ASC";
Ideally I'd like to add the distance data to the mysql result and sort on that. Any ideas?