problem displaying mysql data as xml
Hi all i am trying to use the following code to output mysql data as xml but i keep getting this error:
Quote:
The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
Only one top level element is allowed in an XML document. Error processing resource
i test the code without making xml and it output the data correctly so there is not problem with database connection. I hope you guys show me how to fix this problem and output the xml data correctly.Looking forward for replies.
PHP Code:
<?php
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
$server = "mysql.somesite.com"; // MySQL hostname
$username = "user"; // MySQL username
$password = "test"; // MySQL password
$dbname = "test_db"; // MySQL db name
$db = mysql_connect($server, $username, $password) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());
header('Content-type: application/xml');
$res = mysql_query('SELECT * FROM music1 ORDER by date') or die('<error>'.mysql_error().'</error>');
echo '<playlist>';
while($row = mysql_fetch_assoc($res)){
echo '<song>';
echo '<artist>'.$row['artist'].'</artist>';
echo '<name>'.$row['name'].'</name>';
echo '<image>'.$row['pic'].'</image>';
echo '<rating>'.$row['ids'].'</rating>';
echo '<songid>'.$row['date'].'</songid>';
echo '<totalvotes>'.$row['who_sessid'].'</totalvotes>';
echo '</song>';
}
echo '</playlist>';
?>
Re: problem displaying mysql data as xml
right click -> view source. paste the XML you're getting.