PHP输出到XML时出现while循环错误

时间:2014-09-30 19:53:49

标签: php xml database

我收到错误:第390行第1行的错误:打开和结束标记不匹配:流派第0行和歌曲。

<?php
header("Content-type: text/xml");
echo "<?xml version='1.0' encoding='ISO-8859-1'?>";
echo "<songs>";
$sr = $_GET["sr"];
$conn = new PDO("mysql:host=localhost;dbname=xxxxx;","xxxxx","xxxxx");
$songresults = $conn->query("SELECT * FROM `smashhits` WHERE artist LIKE'%$sr%'");
while($row=$songresults->fetch())
{
echo "<id> ID: $row[ID] </id>";
echo "<song> Song: $row[song] </song>";
echo "<artist> Artist: $row[artist] </artist>";
echo "<year> Year: $row[year] </year>";
echo "<genre> Genre: $row[genre] <genre>";
echo "<quantity> Quantity: $row[quantity] </quantity>";
}
echo "</songs>"
?>

对于知道上述代码出了什么问题的人,我会感激不尽。

1 个答案:

答案 0 :(得分:2)

简单错误:

echo "<genre> Genre: $row[genre] <genre>";

您已打开两个genre代码。我确定你不需要我告诉你应该

echo "<genre> Genre: $row[genre] </genre>";