Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP write to XML guru needed (Code included)

Status
Not open for further replies.

Lucipublishing

Programmer
Jun 13, 2007
2
US
Hi everyone,

I am looking for someone to take a look at my script that is supposed to write to an xml file from a mySQL database. Here's the code:

<code><?php
if(!$dbconnect = mysql_connect('216.154.223.77:3306', 'Video_admin', '1920Capone')) {
echo "Connection failed to the host 'localhost'.";
exit;
} // if
if (!mysql_select_db('joomla_hawaiisoccermagcom')) {
echo "Cannot connect to database 'joomla_hawaiisoccermagcom'";
exit;
} // if

$table_id = 'jos_video_player';
$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';
?>
</code>

It doesn't produce a file like I would like it to, I think it is just some missing syntax. Thanks for the help!
 
Your links are broken. Post an abridged sample (not full one) of what you've got and what you want to get.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top