Salve ho questo codice:
<?php
// Geocode addresses using the Yahoo Geocoding API
// Turning on track_errors stores the latest PHP error in $php_errormsg.
// This allows for more elegant display of the error messages without having to
// code a php error handler, which would be overkill for such a simple script.
ini_set('track_errors',TRUE);
mysql_connect('localhost', 'root', 'password');
mysql_select_db('sintesys1');
// Variabili di configurazione da utilizzare successivamente
$geocode_url = 'http://maps.google.com/maps/api/geocode/json?address=albert%20square&sensor=false';
// Inserisci il tuo appid personalizzato qui
$appid ='sample_appid';
// Ottenere gli indirizzi che non sono stati geocodificati
$address_result = mysql_query("SELECT distinct report_event.luogo, report_event.id
FROM report_event
WHERE report_event.luogo !='' AND report_event.id !=''");
// Se la query MySQL ha restituito alcuna riga , loop attraverso di loro
if(mysql_num_rows($address_result) > 0){
while ($row = mysql_fetch_assoc($address_result)){
// appid è richiesto per ogni chiamata al geocode API yahoo
$row['appid'] = $appid;
// output can be either xml or php
$row['output'] = 'php';
// Store the row id for updating the database and remove from $row array
$id = $row['id'];
unset($row['id']);
// Build the query string for sending the request to yahoo
$query_string = http_build_query($row, '', '&');
// Get latitute / longitude
$response = @file_get_contents($geocode_url.'?'.$query_string) ;
if($response == false){
// If the call to the yahoo api failed, display an error message
echo 'ERROR: '.$php_errormsg;
}
else{
// Get the results of the api call and update the database records
$response_array = unserialize($response);
$lat = mysql_real_escape_string($response_array['ResultSet']['Result']['lat']);
$lon = mysql_real_escape_string($response_array['ResultSet']['Result']['lon']);
$update_result = mysql_query("UPDATE report_event SET lat = '$lat', lon = $lon WHERE report_event.id = $id");
// For each record, let the user know if the update was successful. If not, display the mysql error message generated.
if($update_result == TRUE){
echo "Added lattitude and longitude for {$row['luogo']}.";
}
else{
echo "Unable to add latitude and longitude for {$row['luogo']}
MySQL Error: ".mysql_error();
}
}
echo '<br />';
}
}
else{
echo "Nothing to do.";
}
?>
mi ritorna il seguente errore:
Notice: unserialize(): Error at offset 0 of 167 bytes in C:\xampp\htdocs\r\k.php on line 37
Unable to add latitude and longitude for Serbia MySQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE report_event.id = 5467' at line 1
Sbaglio a scrivere qualcosa?