Hi all,
I am converting some mysql to xml with php but the following line seems to be giving me problems:
$_xml ="<?xml version="1.0" encoding="UTF-8" ?>rn";
this is taken from my script:
<?
$db_name = "Dynamic"; //This is your database Name
$link = mysql_connect("localhost", "root", "") or die("Could not connect to server!");
//This is your table name. This is a one table config to do more table you will need to rework the code.
$table_name = 'Dynamic';
$select_db = mysql_select_db($db_name, $link); // mysql_select_db -- Select a MySQL database
$query = "SELECT * FROM " . $table_name;
$result = mysql_query($query, $link) or die("Could not complete database query");
$num = mysql_num_rows($result); //mysql_num_rows -- Get number of rows in result
$saveloc = "/var/www/html/PICDynamic/test.xml";
if ($num != 0) {
$file= fopen($saveloc, "w"); //fopen -- Opens file or URL
$_xml ="<results>rn";
//--------------------------------------------------------------------------
// This while loop loops throught the data found from the above query and
// generates the XML Doc.
//
//
//--------------------------------------------------------------------------
while ($row = mysql_fetch_array($result)) { //mysql_fetch_array -- Fetch a result row as an associative array, a numeric array, or both.
$xml .=" <item>rn";
$xml .=" <newstitle>" . $row[Ntitle] . "</newstitle>rn";
$xml .=" <date>" . $row[Ndate] . "</date>rn";
$xml .=" <article>" . $row[Narticle] . "</article>rn";
$xml .=" <flag>" . $row[flag] . "</flag>rn";
$xml .=" <link>" . $row[Nlink] . "</link>rn";
$_xml .=" </item>rn";
}
$_xml .="</results>";
//--------------------------------------------------------------------------
// If you would like to save a copy of the XML Doc being created uncomment this
// line and the two lines at the bottom containing fwrite and fclose.
//
//
//--------------------------------------------------------------------------
fwrite($file, $_xml); //fwrite -- Binary-safe file write
fclose($file); //fclose -- Closes an open file pointer
//--------------------------------------------------------------------------
// This will echo the XML file out to the screen so you can view it.
//
//
//
//--------------------------------------------------------------------------
echo $_xml;
} else {
echo "No Records found";
}
?>
I think its the ?> thats causing the problems but any help would be much appreciated !
Thanks in adv
Greg