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 Quote Link to comment 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] Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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] Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.