Trying to cache google maps geocoding

As said I am trying to cache google maps geocoding results.. Anyway what I have so far kinda works but a new sql record is created every time the page loads regardless of whether the record is found or not. I guess it's something obvious and stupid on my part but I struggled to get this far and just can't see it.\[code\]<?php$jobadd = "1000 BURWOOD HWY BURWOOD, VICTORIA, AUSTRALIA";// connect to the databaseinclude('connect-db.php');// get results from database and find needle$result = mysql_query("SELECT * FROM jobaddy") or die(mysql_error()); while($row = mysql_fetch_array( $result )) {$needle = '' . $row['address'] . '';if (strpos($jobadd,$needle) !== false) {$status = "CACHED";$latitude = '' . $row['latitude'] . '';$longitude = '' . $row['longitude'] . '';}else{$status = "GOOGLE";$address2 = "$jobadd, Victoria, Australia";define("MAPS_HOST", "maps.google.com"); $base_url = "http://" . MAPS_HOST . "/maps/api/geocode/xml"; $request_url = $base_url . "?address=" . urlencode($address2) ."&sensor=false"; $xml = new SimpleXMLElement(file_get_contents($request_url)); $latitude = $xml->result->geometry->location->lat;$longitude = $xml->result->geometry->location->lng; // save the data to the databasemysql_query("INSERT jobaddy SET address='$jobadd', latitude='$latitude', longitude='$longitude' ") or die(mysql_error()); }}echo $status;echo '<BR>';echo $jobadd;echo '<BR>';echo 'LAT:';echo $latitude;echo '<BR>';echo 'LON:';echo $longitude;?>\[/code\]
 
Top