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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.