Question : Output XML from SQL

The attached code should output simple XML from a simple SQL SELECT.

However, all of the tags and angle brackets and line feeds are lost.

How do I fix this?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
<?php

$db = mysql_connect('localhost','xxx','xxx') or die("Database error");
mysql_select_db('more', $db);

$query =  "SELECT bag FROM bag";

// Perform Query
$result = mysql_query($query);


$xml_output  = "<?xml version=\"1.0\"?>\n";
$xml_output .= "<bags>\n";

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

 $xml_output  .=  "</bags>";

 echo $xml_output;
?>

Answer : Output XML from SQL

I cleaned up your code so it's nicer. Does that fix the problem and if not can you explain it better :)
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
<?php
ob_start();
$db = mysql_connect('localhost','xxx','xxx') or die("Database error");
mysql_select_db('more', $db);
$query =  "SELECT bag FROM bag";
// Perform Query
$result = mysql_query($query);
echo '<?xml version="1.0"?>';
?>
<bags>
<?php
  while($row = mysql_fetch_assoc($result)) {
?>  <bag><?php echo $row['bag'];?></bag>
<?php
  }
?></bags>
Random Solutions  
 
programming4us programming4us