hi,everyone,i am a newbuy for php world
and i have a problem when i study php
i want to make a script,it works for:
a mysql table,like
title author content date
a1 a2 a3 a4
b1 b2 b3 b4
..........................
and i want to use php ,select it and make a xml to save it ,now i use this
script
<?php
header("Content-type: text/xml");
$host = "localhost";
$user = "root";
$pass = "";
$database = "test";
$linkID = mysql_connect($host, $user, $pass) or die("Could not connect to
host.");
mysql_select_db($database, $linkID) or die("Could not find database.");
$query = "SELECT * FROM blog ORDER BY date DESC";
$resultID = mysql_query($query, $linkID) or die("Data not found.");
$xml_output = "<?xml version=\"1.0\"?>\n";
$xml_output .= "<entries>\n";
for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){
$row = mysql_fetch_assoc($resultID);
$xml_output .= "\t<entry>\n";
$xml_output .= "\t\t<date>" . $row['date'] . "</date>\n";
// Escaping illegal characters
$row['text'] = str_replace("&", "&", $row['text']);
$row['text'] = str_replace("<", "<", $row['text']);
$row['text'] = str_replace(">", ">", $row['text']);
$row['text'] = str_replace("\"", """, $row['text']);
$xml_output .= "\t\t<text>" . $row['text'] . "</text>\n";
$xml_output .= "\t</entry>\n";
}
$xml_output .= "</entries>";
echo $xml_output;
?>
it has no problem,but i want to save a xml file ,like this format
<?xml version="1.0" encoding="GB2312"?>
<Table>
<Record>
<Title>a1</Title>
<Author>a2</Author>
<Content>a3</Content>
<date>2003-06-29</date>
</Record>
<Record>
<Title>b1</Title>
<Author>b2</Author>
<Content>b3</Content>
<date>2003-06-30</date>
</Record>
........
----many record
</Table>
how can i improve this script?
Thanks all