...

View Full Version : PHP and XML



avatar3d
01-12-2010, 10:23 PM
Hello All,
wondering if you could help me? I am using PHP to output my database results in XML. At the moment PHP outputs the XML but its still .php is there a way that PHP can output my results in xml in a seperate document that will be .xml..is this even achieveable?

here is my code;


<?php

$link = mysql_connect("localhost","root","");
mysql_select_db("fashion");

$query = "SELECT ilink,image_name,description FROM gallery";

$results = mysql_query($query);

echo "<?xml version=\"1.0\"?>\n";
echo "<photos path=\"images/\">\n";
while($line = mysql_fetch_array($results)) {
echo "<photo name=\"".$line['image_name']."\" url=\"".$line['ilink']."\">".$line['description']."</photo>\n";
}
echo "</photos>\n";
mysql_close($link);
?>

Thanks in advance

mlseim
01-12-2010, 10:28 PM
Instead of echoing to the screen, open a file called "photos.xml" and write to it.
You also need to form the XML properly, with proper XML tags.
A lot of information about PHP creating XML files using Google.

JAY6390
01-12-2010, 11:27 PM
Add

header ("content-type: text/xml");
before any output (the top of the script is preferable). That should do it. It is possible to rewrite an xml document to a php script and do this, but I believe it should work



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum