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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.