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