Jump to content

Need PHP and XML pro help.


LuciBKen

Recommended Posts

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';
?>

Link to comment
https://forums.phpfreaks.com/topic/55473-need-php-and-xml-pro-help/
Share on other sites

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!!!!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.