XML php不能打印到屏幕上

时间:2017-02-22 14:18:41

标签: php mysql xml maps

我正在尝试使用谷歌地图在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('<','&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 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>';

?>

0 个答案:

没有答案