LuciBKen Posted June 13, 2007 Share Posted June 13, 2007 Hi everyone, I have a question for a php pro who knows how to grab values from a mySQL table and write them to an XML file. The script is shown below and when I run it, it doesn't create an XML file on the server, any ideas? I figure I'm probably missing one line of code that designates the file to write to, and I have no idea what the syntax is to do this. Could someone please help? Thanks! Here's the code: <?php if(!$dbconnect = mysql_connect('***.***.***.***', '******', '*********')) { echo "Connection failed to the host 'localhost'."; exit; } // if if (!mysql_select_db('***************')) { echo "Cannot connect to database '**********'"; exit; } // if $table_id = '********'; $query = "SELECT * FROM $table_id"; $dbresult = mysql_query($query, $dbconnect); // create a new XML document $doc = new DomDocument('1.0'); // create root node $root = $doc->createElement('playlist'); $root = $doc->appendChild($root); // process one row at a time while($row = mysql_fetch_assoc($dbresult)) { // add node for each row $occ = $doc->createElement($table_id); $occ = $root->appendChild($occ); // add a child node for each field foreach ($row as $fieldname => $fieldvalue) { $child = $doc->createElement($fieldname); $child = $occ->appendChild($child); $value = $doc->createTextNode($fieldvalue); $value = $child->appendChild($value); } // foreach } // while // get completed xml document $xml_string = $doc->saveXML(); echo $xml_string; include 'closedb.php'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/55473-need-php-and-xml-pro-help/ Share on other sites More sharing options...
LuciBKen Posted June 13, 2007 Author Share Posted June 13, 2007 Maybe to help everyone who looks at this, here's what my output is in the browser, when it should be what the contents of the xml file look like: after clicking the submit button, here's what I get: test descriptionhttp://www.hawaiisoccermag.com/joomla/templates/hawaiisoccermag.com/images/Video/test.flvhttp://www.hawaiisoccermag.com/joomla/templates/hawaiisoccermag.com/images/Video/thumbnails/test.jpg2007-06-13 19:04:27test2 descriptionhttp://www.hawaiisoccermag.com/joomla/templates/hawaiisoccermag.com/images/Video/test2.flvhttp://www.hawaiisoccermag.com/joomla/templates/hawaiisoccermag.com/images/Video/test2.jpg2007-06-13 19:05:16 Could anyone help please!!!! Quote Link to comment https://forums.phpfreaks.com/topic/55473-need-php-and-xml-pro-help/#findComment-274229 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.