我正在尝试使用谷歌地图在MySQL数据库中存储标记,然后使用PHP调用它并打印到地图。然而,在遵循教程时,我遇到了一个问题。当加载其中包含XML的php页面时,没有任何内容返回到屏幕。我试图通过添加一些console.log()消息来调试,看看我是否正在击中所有区域并且没有发生错误。知道我可能会出错吗?
<?php
echo "<?xml version='1.0' ?>";
echo ("<script>console.log('opening of page');</script>");
function parseToXML($htmlStr)
{
$xmlStr=str_replace('<','<',$htmlStr);
$xmlStr=str_replace('>','>',$xmlStr);
$xmlStr=str_replace('"','"',$xmlStr);
$xmlStr=str_replace("'",''',$xmlStr);
$xmlStr=str_replace("&",'&',$xmlStr);
return $xmlStr;
}
// Opens a connection to a mysqli server
$con = mysqli_connect("localhost","root","XXX","map");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,'SELECT * FROM `markers` WHERE 1');
if (!$result) {
die('Invalid query: ' . mysqli_error());
}
// Start XML file, echo parent node
echo ('<markers>');
// Iterate through the rows, printing XML nodes for each
while ($row = mysqli_fetch_assoc($result)){
echo ("<script>console.log('Heuston, we are in!');</script>");
// Add to XML document node
echo '<marker ';
echo 'name="' . parseToXML($row['name']) . '" ';
echo 'address="' . parseToXML($row['address']) . '" ';
echo 'lat="' . $row['lat'] . '" ';
echo 'lng="' . $row['lng'] . '" ';
echo 'type="' . $row['type'] . '" ';
echo '/>';
}
// End XML file
echo '</markers>';
?>