PDA

View Full Version : PHP output XML



james182
September 19th, 2005, 09:15 PM
hi i'm having trouble with my code, This is how it is outputting:

<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
- <images>
- <pic>
<image>flash/xmlimages/wave.jpg</image>
<caption>Etnies</caption>
<image>flash/xmlimages/chickboard.jpg</image>
<caption>Hello</caption>
<image>flash/xmlimages/babe.jpg</image>
<caption>Swim Wear</caption>
</pic>
</images>

but i need it to output like this:

<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
- <images>
- <pic>
<image>flash/xmlimages/wave.jpg</image>
<caption>Etnies</caption>
</pic>
<pic>
<image>flash/xmlimages/chickboard.jpg</image>
<caption>Hello</caption>
</pic>
<pic>
<image>flash/xmlimages/babe.jpg</image>
<caption>Swim Wear</caption>
</pic>
</images>

heres my code:



<?php

header("Content-type: text/xml");

include ("connect.php");

$xml_output = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\n";
$xml_output .= "<images>\n";

//images
$result = mysql_query("select * from flashgal");

$xml_output .= "\t<pic>\n";

for($x = 0 ; $x < mysql_num_rows($result) ; $x++){
$row = mysql_fetch_assoc($result);
$xml_output .= "\t\t<image>". $row['image'] ."</image>\n";
$xml_output .= "\t\t<caption>". $row['caption'] ."</caption>\n";
}
$xml_output .= "\t</pic>\n";

$xml_output .= "</images>";

echo $xml_output;
?>

b.rich
September 19th, 2005, 09:23 PM
<?php

header("Content-type: text/xml");

include ("connect.php");

$xml_output = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\n";
$xml_output .= "<images>\n";

//images
$result = mysql_query("select * from flashgal");



for($x = 0 ; $x < mysql_num_rows($result) ; $x++){
$row = mysql_fetch_assoc($result);

$xml_output .= "\t<pic>\n";
$xml_output .= "\t\t<image>". $row['image'] ."</image>\n";
$xml_output .= "\t\t<caption>". $row['caption'] ."</caption>\n";
$xml_output .= "\t</pic>\n";
}


$xml_output .= "</images>";

echo $xml_output;
?>