Reputation: 621
Hi im working through the Creating a store locator tutorial on google that can be found here.
https://developers.google.com/maps/articles/phpsqlsearch_v3#findnearsql
My code is
// Select all the rows in the markers table
$query = sprintf("SELECT address, name, lat, lng, ( 3959 * acos( cos( radians('%s') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20",
mysql_real_escape_string("37.414832"),
mysql_real_escape_string("-122.024857"),
mysql_real_escape_string("37.414832"),
mysql_real_escape_string("10"));
$result = mysql_query($sql);
if (!$result)
{
die('Invalid query: ' . mysql_error());
}
else
{
echo 'success';
}
// Start XML file, echo parent node
echo "<markers>\n";
// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
$node = $dom->createElement("marker");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("name", $row['name']);
$newnode->setAttribute("address", $row['address']);
$newnode->setAttribute("lat", $row['lat']);
$newnode->setAttribute("lng", $row['lng']);
$newnode->setAttribute("distance", $row['distance']);
}
// End XML file
echo "</markers>\n";
echo $dom->saveXML();
However when I run the script I get the error message
This page contains the following errors:
error on line 1 at column 1: Document is empty
Below is a rendering of the page up to the first error.
Can anybody see anything wrong with my code?
Upvotes: 2
Views: 870
Reputation: 754
The $dom
object you are trying to create a element for doesn't exist before the 'while' loop.
Create that DOMDocument object first and include the <markers>
rootnode in that object.
Upvotes: 1