Note that there are some explanatory texts on larger screens.

plurals
  1. POGeolocation LONG/LAN in database
    text
    copied!<p>I wrote php code to add adresses to a database. Then I wrote a script to read the long/lan from this adressen and store them in the DB. At this moment there are 10 items in the DB but when i add the 12th or 13th, it loops the whole database again and again to set all this long/lan. I was thinking to count the rows in de DB and then in the update query i just wrote update ... where ID = $rowCount This is my code but i receive an error. Trying to get property of non-object in line 146: $row_cnt = $result->num_rows;</p> <pre><code> public function saveLongLan() { define("MAPS_HOST", "maps.google.com"); define("KEY", "MYKEY"); $link = mysql_connect('localhost', 'root', 'root'); if (!$link) { die('Not connected : ' . mysql_error()); } // Set the active MySQL database $db_selected = mysql_select_db('Foodsquare', $link); if (!$db_selected) { die("Can\'t use db : " . mysql_error()); } $query = "SELECT * FROM tblPlaces WHERE 1"; $result = mysql_query($query); if (!$result) { die("Invalid query: " . mysql_error()); } $row_cnt = $result-&gt;num_rows; $delay = 0; $base_url = "http://" . MAPS_HOST . "/maps/geo?output=xml" . "&amp;key=" . KEY; while ($row = @mysql_fetch_assoc($result)) { $geocode_pending = true; while ($geocode_pending) { $address = $row["Street"]; $id = $row["Id"]; $request_url = $base_url . "&amp;q=" . urlencode($address); $xml = simplexml_load_file($request_url) or die("url not loading"); $status = $xml-&gt;Response-&gt;Status-&gt;code; if (strcmp($status, "200") == 0) { // Successful geocode $geocode_pending = false; $coordinates = $xml-&gt;Response-&gt;Placemark-&gt;Point-&gt;coordinates; //explode functie breekt een string af vanaf een bepaald teken en stopt hem dan in een array $coordinatesSplit = explode(',', $coordinates); // formaat: Longitude, Latitude, Altitude $lat = $coordinatesSplit[1];//getal = plaats in array $lng = $coordinatesSplit[0]; $query = sprintf("UPDATE tblPlaces". " SET lat = '%s', lng = '%s' " . " WHERE Id = '" . $row_cnt . "' LIMIT 1;", mysql_real_escape_string($lat), mysql_real_escape_string($lng), mysql_real_escape_string($id)); $update_result = mysql_query($query); if (!$update_result) { die("Invalid query: " . mysql_error()); } } else if (strcmp($status, "620") == 0) { // sent geocodes too fast $delay += 100000; } else { // failure to geocode $geocode_pending = false; echo "Address " . $address . " failed to geocoded. "; echo "Received status " . $status . " \n"; } usleep($delay); } } } } </code></pre> <p>I didn't change anything in the update statement yet.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload