[SOLVED] Zip Code Lookup is slow
Posted: Tue Jun 07, 2005 1:50 pm
Hi,
I'm using a simple zip code database, with about 42,000 rows. I've written a function to take an entered zip code, and compare those latitude and longitude values to those of each row in the database to calculate the distance between them. If the distance returned is less than the given radius, it should add that zipcode to the array.
Mine seems to keep getting stuck in an infinate loop, (or is taking many hours to complete, and I've never finished it). I have compared my code to others on the net which do this function in less than a second.
Any ideas?
I'm using a simple zip code database, with about 42,000 rows. I've written a function to take an entered zip code, and compare those latitude and longitude values to those of each row in the database to calculate the distance between them. If the distance returned is less than the given radius, it should add that zipcode to the array.
Mine seems to keep getting stuck in an infinate loop, (or is taking many hours to complete, and I've never finished it). I have compared my code to others on the net which do this function in less than a second.
Any ideas?
Code: Select all
function InRadius($zip, $radius) {
// Get The Lon and Lat for the entered zip code
$this->GetByZip($zip);
// Loop Through Query, and check distance
$DataLookup = New MySQL;
$query = "SELECT * FROM zipcode ORDER BY zipcode";
$i = 0;
while ($row = $DataLookup->queryTOobject($query)) {
$rowlat = $row->latitude;
$rowlon = $row->longitude;
$dist = Distance($this->lat, $this->lon, $rowlat, $rowlon);
if ($dist <= $radius) {
$zipsarr[$i] = $row->zipcode;
}
}
}