kyle422
02-27-2010, 05:59 PM
I'm not a very experience coder. I know very little about php except simple commands. I need to change these two scripts from PHP4 to PHP5. Please help. Thanks. (The functions.php script doesn't have any issues.)
<?
include "functions.php";
echo "max_execution_time set to 500 seconds, was set to: " . ini_set("max_execution_time", "500") . "<br>";
$_con = getConnected();
$result = MySQL_Query("
SELECT o.mlsNo, b.mlsNo, b.latitude, b.longitude
FROM b_fla_data_backup b
LEFT JOIN b_fla_data o ON b.mlsNo = o.mlsNo
WHERE o.mlsNo IS NOT NULL
");
while ( $row = MySQL_Fetch_Assoc($result) ){
if ( $row['latitude'] != '-1' AND $row['longitude'] != '-1' ){
$query = "UPDATE b_fla_data SET latitude = '" . $row['latitude'] . "', longitude = '" . $row['longitude'] . "' WHERE mlsNo = '" . $row['mlsNo'] . "' LIMIT 1";
$uResult = MySQL_Query($query);
if ( !$uResult ){
echo $query . '<br>' . MYSQL_Error() . '<br><br>';
}
}
}
MySQL_Close($_con);
?>
Second Script
<?
include "functions.php";
echo "max_execution_time set to 1000 seconds, was set to: " . ini_set("max_execution_time", "1000") . "<br>";
define("GMAPS_KEY", "ABQIAAAA1JfdgAmVttcHXZGm51HjWBRXsEs39GKiZK6VsNfActQoMKLFThSAuftczHqaaZbxEXKiVFUQSafLHQ");
// code for google maps
define("GMAPS_URL", "http://maps.google.com/maps/geo?");
// url of responder
define("GMAPS_OUTPUT", "csv");
// select type of output
$_con = getConnected();
$result = MySQL_Query("SELECT uid, streetNo, streetDir, streetName, streetSuffix, city, state FROM b_fla_data WHERE longitude = '0' AND latitude = '0' LIMIT 1000");
$delay = 0;
while ( $row = MySQL_Fetch_Assoc($result) ){
$address = '';
if ( !empty ( $row['streetNo'] ) ){
$address .= $row['streetNo'];
}
if ( !empty( $row['streetDir'] ) ){
// $address .= ' ' . $row['streetDir'];
}
if ( !empty( $row['streetName'] ) ){
$address .= ' ' . $row['streetName'];
}
if ( !empty( $row['streetSuffix'] ) ){
if ( $row['streetSuffix'] == 'LA' ){
$row['streetSuffix'] = 'Ln';
}
if ( $row['streetSuffix'] == 'AV' ){
$row['streetSuffix'] = 'AVE';
}
$address .= ' ' . $row['streetSuffix'];
}
if ( !empty( $row['city'] ) ){
if ( $row['city'] == "MERRITT ISL" ){
$row['city'] = eregi_replace("MERRITT ISL", "MERRITT ISLAND", $row['city']);
}
if ( $row['city'] == "BAREFOOT BAY" ){
$row['city'] = eregi_replace("BAREFOOT BAY", "SEBASTIAN", $row['city']);
}
if ( $row['city'] == "W MELBOURNE" ){
$row['city'] = eregi_replace("W MELBOURNE", "MELBOURNE", $row['city']);
}
if ( $row['city'] == "INDIAN HARB BCH" ){
$row['city'] = eregi_replace("INDIAN HARB BCH", "INDIAN HARBOUR BEACH", $row['city']);
}
$row['city'] = eregi_replace("PT ST JOHN", "PORT ST JOHN", $row['city']);
$address .= ', ' . $row['city'];
}
if ( !empty( $row['state'] ) ){
$address .= ', ' . $row['state'];
}
$done = false;
while ( !$done ){
$response = file_get_contents(GMAPS_URL . "q=" . urlencode($address) . "&output=" . GMAPS_OUTPUT . "&key=" . GMAPS_KEY . "&sensor=false" );
usleep(300000);
$response = explode(",", $response);
if ( $response[0] == "200" ){
$update_result = MySQL_Query("UPDATE b_fla_data SET latitude = '" . $response[2] . "', longitude = '" . $response[3] . "' WHERE uid = '" . $row['uid'] . "'");
$done = true;
} else if ( $response[0] == "620" ){
$delay = $delay + 100000;
} else {
echo 'problem s geocodovanim adresy: <strong>' . $address . '</strong>, kod: <strong>' . $response[0] . '</strong><br>';
$done = true;
$update_result = MySQL_Query("UPDATE b_fla_data SET latitude = '-1', longitude = '-1' WHERE uid = '" . $row['uid'] . "'");
}
usleep($delay);
}
}
MySQL_Close($_con);
?>
<?
include "functions.php";
echo "max_execution_time set to 500 seconds, was set to: " . ini_set("max_execution_time", "500") . "<br>";
$_con = getConnected();
$result = MySQL_Query("
SELECT o.mlsNo, b.mlsNo, b.latitude, b.longitude
FROM b_fla_data_backup b
LEFT JOIN b_fla_data o ON b.mlsNo = o.mlsNo
WHERE o.mlsNo IS NOT NULL
");
while ( $row = MySQL_Fetch_Assoc($result) ){
if ( $row['latitude'] != '-1' AND $row['longitude'] != '-1' ){
$query = "UPDATE b_fla_data SET latitude = '" . $row['latitude'] . "', longitude = '" . $row['longitude'] . "' WHERE mlsNo = '" . $row['mlsNo'] . "' LIMIT 1";
$uResult = MySQL_Query($query);
if ( !$uResult ){
echo $query . '<br>' . MYSQL_Error() . '<br><br>';
}
}
}
MySQL_Close($_con);
?>
Second Script
<?
include "functions.php";
echo "max_execution_time set to 1000 seconds, was set to: " . ini_set("max_execution_time", "1000") . "<br>";
define("GMAPS_KEY", "ABQIAAAA1JfdgAmVttcHXZGm51HjWBRXsEs39GKiZK6VsNfActQoMKLFThSAuftczHqaaZbxEXKiVFUQSafLHQ");
// code for google maps
define("GMAPS_URL", "http://maps.google.com/maps/geo?");
// url of responder
define("GMAPS_OUTPUT", "csv");
// select type of output
$_con = getConnected();
$result = MySQL_Query("SELECT uid, streetNo, streetDir, streetName, streetSuffix, city, state FROM b_fla_data WHERE longitude = '0' AND latitude = '0' LIMIT 1000");
$delay = 0;
while ( $row = MySQL_Fetch_Assoc($result) ){
$address = '';
if ( !empty ( $row['streetNo'] ) ){
$address .= $row['streetNo'];
}
if ( !empty( $row['streetDir'] ) ){
// $address .= ' ' . $row['streetDir'];
}
if ( !empty( $row['streetName'] ) ){
$address .= ' ' . $row['streetName'];
}
if ( !empty( $row['streetSuffix'] ) ){
if ( $row['streetSuffix'] == 'LA' ){
$row['streetSuffix'] = 'Ln';
}
if ( $row['streetSuffix'] == 'AV' ){
$row['streetSuffix'] = 'AVE';
}
$address .= ' ' . $row['streetSuffix'];
}
if ( !empty( $row['city'] ) ){
if ( $row['city'] == "MERRITT ISL" ){
$row['city'] = eregi_replace("MERRITT ISL", "MERRITT ISLAND", $row['city']);
}
if ( $row['city'] == "BAREFOOT BAY" ){
$row['city'] = eregi_replace("BAREFOOT BAY", "SEBASTIAN", $row['city']);
}
if ( $row['city'] == "W MELBOURNE" ){
$row['city'] = eregi_replace("W MELBOURNE", "MELBOURNE", $row['city']);
}
if ( $row['city'] == "INDIAN HARB BCH" ){
$row['city'] = eregi_replace("INDIAN HARB BCH", "INDIAN HARBOUR BEACH", $row['city']);
}
$row['city'] = eregi_replace("PT ST JOHN", "PORT ST JOHN", $row['city']);
$address .= ', ' . $row['city'];
}
if ( !empty( $row['state'] ) ){
$address .= ', ' . $row['state'];
}
$done = false;
while ( !$done ){
$response = file_get_contents(GMAPS_URL . "q=" . urlencode($address) . "&output=" . GMAPS_OUTPUT . "&key=" . GMAPS_KEY . "&sensor=false" );
usleep(300000);
$response = explode(",", $response);
if ( $response[0] == "200" ){
$update_result = MySQL_Query("UPDATE b_fla_data SET latitude = '" . $response[2] . "', longitude = '" . $response[3] . "' WHERE uid = '" . $row['uid'] . "'");
$done = true;
} else if ( $response[0] == "620" ){
$delay = $delay + 100000;
} else {
echo 'problem s geocodovanim adresy: <strong>' . $address . '</strong>, kod: <strong>' . $response[0] . '</strong><br>';
$done = true;
$update_result = MySQL_Query("UPDATE b_fla_data SET latitude = '-1', longitude = '-1' WHERE uid = '" . $row['uid'] . "'");
}
usleep($delay);
}
}
MySQL_Close($_con);
?>