Jump to content

PHP to XML


timmah1

Recommended Posts

Can someone help me with this?

I'm not sure what the problem is.

I want to select items out of my database, and parse them as XML, the problem I'm having is that the XML is not showing up the variables.

Here is my PHP page:
[code]
$query = "SELECT * FROM database";
$mysql_result = mysql_query($query);

define('NEWLINE',  "\n", true);

$xml  = '<?xml version="1.0" encoding="iso-8859-1"?>' . NEWLINE;

$xml .= '<songs>' . NEWLINE;       

while($myrow = mysql_fetch_assoc($mysql_result))
$file = $myrow['file'];
$name = $myrow['name'];
{

    $xml .= '<song name='.$name.' file='.$file.'>'. NEWLINE;
}

$xml .= '</songs>';       

$fp = fopen('file.xml','w');
fwrite($fp, $xml);
fclose($fp);
[/code]

And what it parses is this:
[code]
<?xml version="1.0" encoding="iso-8859-1"?>
<songs>
<song name= file=>
</songs>
[/code]


Can anybody help me clarify this?

thanks
Link to comment
https://forums.phpfreaks.com/topic/30263-php-to-xml/
Share on other sites

[code]
while($myrow = mysql_fetch_assoc($mysql_result))
$file = $myrow['file'];
$name = $myrow['name'];
{

    $xml .= '<song name='.$name.' file='.$file.'>'. NEWLINE;
}
[/code]

Your while loop is effectively:
[code]
while($myrow = mysql_fetch_assoc($mysql_result))
$file = $myrow['file'];
[/code]

Try this:
[code]
while($myrow = mysql_fetch_assoc($mysql_result)){
    $file = $myrow['file'];
    $name = $myrow['name'];
    $xml .= '<song name='.$name.' file='.$file.'>'. NEWLINE;
}
[/code]
Link to comment
https://forums.phpfreaks.com/topic/30263-php-to-xml/#findComment-139181
Share on other sites

ok, it worked like one time, and now it doesn't.

this is what it's outputting:
[code]
<?xml version="1.0" encoding="iso-8859-1"?>
<songs>
</songs>
[/code]


It works for awhile, and then it don't.

I fixed it so that it parses the quotes
[code]
$query = "SELECT * FROM database ";
$mysql_result = mysql_query($query);


define('NEWLINE',  "\n", true);



$xml  = '<?xml version="1.0" encoding="iso-8859-1"?>' . NEWLINE;


$xml .= '<songs>' . NEWLINE;       


while($myrow = mysql_fetch_assoc($mysql_result)){
    $song = $myrow['song'];
    $name = $myrow['name'];
    $xml .= '<song name="'.$song.'" file="'.$name.'">'. NEWLINE;
}



$xml .= '</songs>';       



$fp = fopen('playlist.xml','w');
fwrite($fp, $xml);
fclose($fp);

?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/30263-php-to-xml/#findComment-139206
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.