discourse-legacysite-perl/site/googlemaps/coaches_xml.php
2024-06-17 22:42:14 +10:00

52 lines
1.3 KiB
PHP

<?php
header("Content-type: text/xml");
require("phpsqlajax_dbinfo.php");
function parseToXML($htmlStr)
{
$xmlStr=str_replace('<','&lt;',$htmlStr);
$xmlStr=str_replace('>','&gt;',$xmlStr);
$xmlStr=str_replace('"','&quot;',$xmlStr);
$xmlStr=str_replace("'",'&#39;',$xmlStr);
$xmlStr=str_replace("&",'&amp;',$xmlStr);
return $xmlStr;
}
// Opens a connection to a MySQL server
$connection=mysql_connect ($host, $username, $password);
if (!$connection) {
die('Not connected : ' . mysql_error());
}
// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());
}
// Select all the rows in the markers table
$query = "SELECT * FROM gforum_Coaches WHERE coach_lat <> 0 AND coach_lng <> 0";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
// Start XML file, echo parent node
echo '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL;
echo '<markers>'.PHP_EOL;
// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
echo '<marker';
echo ' name="' . parseToXML($row['coach_name']) . '" ';
echo 'lat="' . $row['coach_lat'] . '" ';
echo 'lng="' . $row['coach_lng'] . '" ';
echo '/>'.PHP_EOL;
}
// End XML file
echo '</markers>';
?>