I am writing a Javascript which shows latitude and longitude on google maps. It takes input data from an xml file. I have the latitude and longitude values stored in my MySql database. Now, all I need to do is populate 3 fields --- Name, Lat and Lon on an xml file.
I have gathered and written the following code but it seems to give an error
Parse error: syntax error, unexpected T_ELSE .... on line 52
The xml file I need should be in this order...
<?xml version="1.0"?>
<markers>
<marker>
<name>Yaz01</name>
<lat>52.5914943</lat>
<lng>-2.1328675</lng>
</marker>
<marker>
<name>Yaz02</name>
<lat>52.45041265041157</lat>
<lng>-1.9247746467590332</lng>
</marker>
<marker>
<name>Yaz03</name>
<lat>52.584720758388734</lat>
<lng>-2.125253677368164</lng>
</marker>
</markers>
Here is the code I've written for your reference ...
<!DOCTYPE html>
<html>
<head>
<title>Google Maps</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="scripts/jquery-1.4.1.min.js"></script>
<script type="text/javascript" src="scripts/markers.js">
</script>
</head>
<body>
<?php
include 'datalogin.php';
$table_name = 'draininfo';
$db = mysql_select_db($dbName, $link);
$query = "select DRAINNAME, LATITUDE, LONGITUDE from " . $table_name;
$result = mysql_query($query, $connection) or die("Could not complete database query");
$num = mysql_num_rows($result);
if ($num != 0) {
$file= fopen("results.xml", "w");
$_xml =<<<XML
<?xml version="1.0" encoding="UTF-8" ?>\r\n
XML;
$_xml .="<markers>\r\n";
while ($row = mysql_fetch_array($result)) {
$_xml .="\t<marker>\r\n";
$_xml .="\t<name>" . $row["DRAINNAME"] . "<\"name>\r\n";
$_xml .="\t<lat>" . $row["LATITUDE"] . "<\"lat>\r\n";
$_xml .="\t<lon>" . $row["LONGITUDE"] . "<\"lon>\r\n";
$_xml .="\t</marker>\r\n";
$_xml .="</markers>";
fwrite($file, $_xml);
fclose($file);
echo "XML has been written. <a href=\"results.xml\">View the XML.</a>";
}
else {
echo "No Records found";
}
}
?>
<div id="map"></div>
<div ><input type="button" id="showmarkers" value="Show Markers" /></div>
</body>
</html>