Example #1
0
//	$arrResult = $dbh->query("SELECT distinct mail_zip, zip_lat, zip_lon
//					FROM sys_users
//						WHERE mail_zip is not null");
$arrResult = $dbh->query("\n            SELECT distinct mail_zip, zip_lat, zip_lon\n                                FROM sys_users\n                                    WHERE mail_zip is not null AND mail_zip NOT IN (\n                                        SELECT service_addr_zip FROM report_groups\n                                    )\n\n            UNION\n            SELECT distinct service_addr_zip as mail_zip, zip_lat, zip_lon\n             FROM report_groups\n                WHERE service_addr_zip is not null\n    ");
$dom = new DOMDocument();
//Process the list of ZIPs to be submitted to the service
$LatLonList = null;
$LatLonArray = array();
$i = 0;
foreach ($arrResult as $row) {
    if ($row['zip_lat'] == 0) {
        //ZIP needs to be looked up from the service
        echo "NEW zip code:" . print_r(substr($row['mail_zip'], 0, 5), true) . "\n";
        try {
            //Submit just the first 5 digits of the IP code
            $dom->loadXML($soapclient->LatLonListZipCode(substr($row['mail_zip'], 0, 5)));
            $LatLon = $dom->getElementsByTagName('latLonList')->item(0)->nodeValue;
        } catch (Exception $e) {
            echo "Invalid ZIP or other issue\n";
            $LatLon = '0,0';
        }
        if (strlen($LatLon) > 2) {
            //Good latLon value
            echo "NEW zip location:" . $LatLon . "\n";
            //Break the lat/lon value string into two numerical parts
            $Lat = substr($LatLon, 0, strpos($LatLon, ','));
            //get the lat
            $Lon = strstr($LatLon, ',');
            //get the lon
            $Lon = substr($Lon, 1);
            //Write the new values back to the DB