I wonder if I could get some help with the following code. It's designed to find, from within a mySQL database, restaurants that are within a certain radius of a particular hotel. The information is output to an XML file which then populates a Google map. The variables for the coordinates of the hotel itself are set as $center_lat and $center_lng. The restaurant data is in a table called "dining".
I've tested the server output and it's connecting OK.
I've checked that DOM_XML is enabled on the server, too.
Here's the code (minus server connection details):
<?
$center_lat="48";
$center_lng="-123";
$radius="25";
// Start XML file, create parent node
$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node);
// Search the rows in the markers table
$query = sprintf("SELECT restname, address1, lat, lng, ( 3959 * acos( cos( radians('%s') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS distance FROM dining HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20",
mysql_real_escape_string($center_lat),
mysql_real_escape_string($center_lng),
mysql_real_escape_string($center_lat),
mysql_real_escape_string($radius));
$result = mysql_query($query);
if (!$result) {
die("Invalid query: " . mysql_error());
}
header("Content-type: text/xml");
// Iterate through the rows, adding XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
$node = $dom->createElement("marker");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("name", $row['restname']);
$newnode->setAttribute("address", $row['address1']);
$newnode->setAttribute("lat", $row['lat']);
$newnode->setAttribute("lng", $row['lng']);
$newnode->setAttribute("distance", $row['distance']);
}
echo $dom->saveXML();
?>