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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic XML with PHP

Status
Not open for further replies.

fanfavorite

IS-IT--Management
Apr 3, 2003
5
CA
I have a flash player that reads in an XML file:


This works fine, but when I try to work use a php file:


the drop down menu of the flash does not display, even though if you go to audioxml.php it displays fine. The songs still play through as in the XML file, but just doesn't load the playlist drop down correctly. In IE7, if I hit refresh, the menu displays fine (almost like it didn't finish loading the first time). In Firefox and other browsers, it just stays without the proper list in the drop down. The php file is like:

Code:
header('Content-Type: text/xml'); 
echo '<?xml version="1.0" encoding="iso-8859-1"?>';
$url = "../../media/mp3/"; 
include('../includes/connection.php');

echo "\n<gallery>";

$CatArray[] = "0";
$count = 1;

$q = mysql_query("SELECT * FROM MusicPlayer ORDER BY Category");

while($f = mysql_fetch_array($q)) { 
if (in_array($f[Category], $CatArray) == false) {
if ($count != 1) {
echo "\n\t</category>";
}
echo "\n\t";
echo '<category name="'.$f[Category].'">';
$CatArray[] = $f[Category];
}

$artist = strtoupper($f[Artist]);
$song = strtoupper($f[SongName]);
echo "\n\t\t";
echo '<item mp3Path="'.$url.$f[Filename].'" played="0"><![CDATA[<font face="Font" color="#198a56">'.$artist.': </font><font face="Font" color="#FFFFFF">'.$song.'</font>]]></item>';
$count++;
}
echo "\n\t</category>";
echo "\n</gallery>";

I have also tried:
Code:
<? 
$url = "../../media/mp3/";
include('../includes/connection.php');

$doc = new DOMDocument();
$doc->formatOutput = true;

$r = $doc->createElement("gallery");
$doc->appendChild($r);

$CatArray[] = "0";
$count = 1;

$q = mysql_query("SELECT * FROM MusicPlayer ORDER BY Category");

while($f = mysql_fetch_array($q)) { 
if (in_array($f[Category], $CatArray) == false) {
if ($count != 1) {
$r->appendChild($b);
}

$b = $doc->createElement("category");
$b_attr1 = $doc->createAttribute('name');
$b->appendChild($b_attr1); 
$b_attr1->appendChild($doc->createTextNode($f[Category])); 
$CatArray[] = $f[Category];
}
$artist = strtoupper($f[Artist]);
$song = strtoupper($f[SongName]);
$item = $doc->createElement("item");
$item_attr1 = $doc->createAttribute('mp3Path');
$item->appendChild($item_attr1);
$item_attr1->appendChild($doc->createTextNode($url.$f[Filename]));
$item_attr2 = $doc->createAttribute('played');
$item->appendChild($item_attr2);
$item_attr2->appendChild($doc->createTextNode('0'));
$itemdata = '<font face="Font" color="#198a56">'.$artist.': </font><font face="Font" color="#FFFFFF">'.$song.'</font>';
$itemdata_cd = $doc->createCDATASection($itemdata);
$item->appendChild($itemdata_cd);
$b->appendChild($item);
$count++;
}

$r->appendChild($b);
echo $doc->saveXML();  
?>

Does anyone know why it would not be loading correctly? Is there a better way to create an XML file from dynamic MySQL data?

Thanks everyone.
 
[1] Similarly for other instances to refer to the resultset's fields.
>$f[Category]
[tt]$f['Category'][/tt]
 
[2] Make sure the <?xml ... ?> prolog line be the first to echo. Nothing before it. ff is very strict on this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top