Hey all...
I'm having a problem building a certain XML file structure while
looping through results of a mySQL db. I pasted the code below to give
an idea of the structure I'm trying to build.
Any hints would be helpful!!!
Thanks,
-Gerry
<?php
header("Content-type: text/xml");
// ** MySQL settings ** //
$host = "localhost";
$user = "username";
$pass = "password";
$database = "dbname";
$table = "videos";
$linkID = mysql_connect($host, $user, $pass) or die("Could not connect
to host.");
mysql_select_db($database, $linkID) or die("Could not find database.");
$query = "SELECT * FROM $table";
$resultID = mysql_query($query, $linkID) or die("Data not found.");
$xml_output = "<?xml version=\"1.0\"?>\n";
//auto
$xml_output .= "<node label='ª Auto' value='1'>\n";
for($x = 0 ; $x < mysql_num_rows($resultID); $x++){
$row = mysql_fetch_assoc($resultID);
if ($row['cat'] == 'auto'){
$xml_output .= "\t<vid label='" . $row['title'] . "' cat='" .
$row['cat'] . "' data='" . $row['file'] . "'></vid>\n";
}
}
$xml_output .= "</node>";
//retail
$xml_output .= "<node label='ª Retail' value='2'>\n";
for($z = 0 ; $z < mysql_num_rows($resultID); $z++){
$row = mysql_fetch_assoc($resultID);
if ($row['cat'] == 'retail'){
$xml_output .= "\t<vid label='" . $row['title'] . "' cat='" .
$row['cat'] . "' data='" . $row['file'] . "'></vid>\n";
}
}
$xml_output .= "</node>";
echo $xml_output;
?>