Zip Code Radius
I am using the following function from phpclasses.org.
How can I gues this to return also the distance for each zip code?
PHP
function inradius($zip,$radius)
{
$query2="SELECT * FROM zips WHERE zip='$zip'";
$row = $db->get($query2);
$lat=$row["lat"];
$lon=$row["lon"];
$query2="SELECT zipcode FROM zips WHERE (POW((69.1*(lon-"$lon")*cos($lat/57.3)),"2")+POW((69.1*(lat-"$lat")),"2"))<($radius*$radius) ";
$result = $database->query($query2);
if($result->count()<>0) {
while($row = $result->fetch()) {
$zips[$i]=$row["zipcode"];
$i++;
}
}
}else{
return array();
}
return $zips;
}
View Replies !
Query Which Gets Rows Based On A Radius, Lon And Lat Doesn't Work?
I have found this query which gets rows based on a radius. I need this for zip codes based on lon and lat's.
$sql2 = "SELECT * FROM table as z WHERE (SQRT( (69.1 * (".$userLat." - z.lat)) * (69.1 * (".$userLat." - z.lat)) + (53.0 *(".$userLong." - z.lon)) * (53.0 *(".$userLong." - z.lon))) <= ".$userRadius." )";
return $sql2;
$res = mysql_query($sql2, $connDB) or die(mysql_error());
$row = mysql_fetch_assoc($res);
based on a test zip code gives a result like
SELECT * FROM table as z WHERE (SQRT( (69.1 * (52.399834 - z.lat)) * (69.1 * (52.399834 - z.lat)) + (53.0 *(4.840762 - z.lon)) * (53.0 *(4.840762 - z.lon))) <= 100 )
the lat and lon of the test zip code are right. As you can see z.lat and z.lon don't get any value. And these would be every lat and lon in table.
In my db table lon and lat are decimal(10,6) type with a default value of 0.000000
View Replies !