How to put XML content in reverse order?

theone759

New Member
I tried a few solutions already posted here, but nothing seems to work. That might be, because I am really not that familiar with php or xml. I just need to output xml for xcoding. So hopefully someone can shed some light, on how I can reverse the order of my xml, so that the last entry is on top. My last try what with: \[code\]$query = array_reverse($doc->xpath('query'));\[/code\]but it did not like it ,e.g. it did not work. So here is my code in order to create my xml document: \[code\]<?php if(!$dbconnect = mysql_connect('localhost', '-', '-')) {echo "Connection failed to the host 'localhost'.";exit;} // ifif (!mysql_select_db('-')) {echo "Cannot connect to database '-'";exit;} // if$table_id = 'table1';$query = "SELECT Name,Age,Sex FROM $table_id";$dbresult = mysql_query($query, $dbconnect);// 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 timewhile($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 fieldforeach ($row as $fieldname => $fieldvalue) {$child = $doc->createElement($fieldname);$child = $occ->appendChild($child);$value = http://stackoverflow.com/questions/10571651/$doc->createTextNode($fieldvalue);$value = $child->appendChild($value);} // foreach} // while// get completed xml document$xml_string = $doc->saveXML();$doc->save("yolo.xml") //echo $xml_string;?> \[/code\]
 
Back
Top