export mysql data into xml file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • milas57
    New Member
    • May 2007
    • 14

    export mysql data into xml file

    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("SE LECT * from user " );
    // create a new XML document
    $doc = new DomDocument('1. 0');
    // create root node
    $root = $doc->createElement( 'root');
    $root = $doc->appendChild($r oot);
    // process one row at a time
    while($row = mysql_fetch_ass oc($result)) {
    // add node for each row
    $occ = $doc->createElement( $dbproduct);
    $occ = $root->appendChild($o cc);
    // add a child node for each field
    foreach ($row as $fieldname => $fieldvalue) {
    $child = $doc->createElement( $fieldname);
    $child = $occ->appendChild($c hild);
    $child = $doc->createElement( $fieldname);
    $child = $occ->appendChild($c hild);

    } // 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>
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    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($c hild);
    $child = $doc->createElement( $fieldname);
    $child = $occ->appendChild($c hild);[/PHP]

    Comment

    Working...