timmah1 Posted December 11, 2006 Share Posted December 11, 2006 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 More sharing options...
roopurt18 Posted December 11, 2006 Share Posted December 11, 2006 [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 More sharing options...
timmah1 Posted December 11, 2006 Author Share Posted December 11, 2006 Now it does this:[code]<?xml version="1.0" encoding="iso-8859-1"?><songs><song name=name file=file></songs>[/code]It's not recognizing the variable for some reason Link to comment https://forums.phpfreaks.com/topic/30263-php-to-xml/#findComment-139185 Share on other sites More sharing options...
timmah1 Posted December 11, 2006 Author Share Posted December 11, 2006 Nevermind, I got it to workThanks for the help Link to comment https://forums.phpfreaks.com/topic/30263-php-to-xml/#findComment-139189 Share on other sites More sharing options...
roopurt18 Posted December 11, 2006 Share Posted December 11, 2006 You should keep in mind that valid XML requires attributes to be placed in quotes. Link to comment https://forums.phpfreaks.com/topic/30263-php-to-xml/#findComment-139194 Share on other sites More sharing options...
timmah1 Posted December 11, 2006 Author Share Posted December 11, 2006 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 More sharing options...
timmah1 Posted December 11, 2006 Author Share Posted December 11, 2006 I have it working now.But now I'm having a different problem, It's only listing one value.I put in 2 fields in the database, both or different, but the xml is only producing 1 of the entries.Anybody have an idea? Link to comment https://forums.phpfreaks.com/topic/30263-php-to-xml/#findComment-139241 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.