By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,914 Members | 562 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,914 IT Pros & Developers. It's quick & easy.

export mysql data into xml file

P: 14
hello everyone
im new to php and mysql i been trying to export mysql data in an xml file my code below i have problem picking data in the database to display in the xml file, the xml file only show the field in the datbase any help please thank

---------------------------
code
$result = MYSQL_QUERY("SELECT * from user " );
// create a new XML document
$doc = new DomDocument('1.0');
// create root node
$root = $doc->createElement('root');
$root = $doc->appendChild($root);
// process one row at a time
while($row = mysql_fetch_assoc($result)) {
// add node for each row
$occ = $doc->createElement($dbproduct);
$occ = $root->appendChild($occ);
// add a child node for each field
foreach ($row as $fieldname => $fieldvalue) {
$child = $doc->createElement($fieldname);
$child = $occ->appendChild($child);
$child = $doc->createElement($fieldname);
$child = $occ->appendChild($child);

} // foreach
} // while

// get completed xml document
$xml_string = $doc->saveXML();

//echo $xml_string;
$doc->save('test.xml');
---------------------------------------------------
xml file
<?xml version='1.0
<root>
<user>
<id></id>
<name>/name<>
</user>
</root>
Jan 31 '08 #1
Share this Question
Share on Google+
1 Reply

code green
Expert 100+
P: 1,726
the xml file only show the field in the datbase
You don't actually use $fieldvalue only $fieldname[PHP]foreach ($row as $fieldname => $fieldvalue) {[/PHP]How do you expect $fieldvalue to appear if you do not use it?
[PHP]$child = $doc->createElement($fieldname);
$child = $occ->appendChild($child);
$child = $doc->createElement($fieldname);
$child = $occ->appendChild($child);[/PHP]
Feb 1 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.