简体   繁体   English

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

[英]PHP output to XML with a while loop error

I Get the error: error on line 1 at column 390: Opening and ending tag mismatch: genre line 0 and songs. 我收到错误:第1行第390列的错误:开头和结尾标签不匹配:流派第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>" ?> 

I would be thankful for anyone who knows what's going wrong with the code above. 我将感谢任何知道上述代码出了什么问题的人。

Simple error: 简单错误:

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

You've opened two genre tags. 您已经打开了两个genre标签。 I'm sure you don't need me to tell you that it should be 我确定您不需要我告诉您应该

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM