# PHP output XML

**URL:** <https://forum.kirupa.com/t/php-output-xml/163126>\
**Category:** programming\
**Created:** [September 20, 2005, 1:15am UTC](https://forum.kirupa.com/t/php-output-xml/163126 "2005-09-20T01:15:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![james182](https://avatars.discourse-cdn.com/v4/letter/j/278dde/32.png) [@james182](https://forum.kirupa.com/u/james182)\
**Post date:** [September 20, 2005, 1:15am UTC](https://forum.kirupa.com/t/php-output-xml/163126/1 "2005-09-20T01:15:36Z")

</div>

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
 
<?php 

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

include ("connect.php");

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

	//images
	$result = mysql_query("select * from flashgal");
	
	$xml_output .= "	<pic>
";
	
for($x = 0 ; $x < mysql_num_rows($result) ; $x++){ 
	$row = mysql_fetch_assoc($result); 
	   $xml_output .= " <image>". $row['image'] ."</image>
";
	$xml_output .= " <caption>". $row['caption'] ."</caption>
";
	}
	$xml_output .= "	</pic>
"; 
	
$xml_output .= "</images>"; 

echo $xml_output; 
?> 

```
