This stuff has been messing with me all day. . . But in the end, I found that I couldn't achieve the effect I imagined. . . What a shame. . . It seems that PHP needs to be strengthened for XML. . . If anyone has research on this. Welcome to write to discuss. . .
First create the table:
CREATE TABLE books (
bookid int(4) NOT NULL auto_increment,
bookname varchar(100) NOT NULL,
bookauth varchar(50) NOT NULL,
bookpublisher varchar(50) NOT NULL,
bookpubdate datetime NOT NULL,
bookurl varchar(50) NOT NULL,
KEY bookid (bookid),
);
Then. . . This section is the source code for converting data from MYSQL into XML:
$connect_id=mysql_connect("localhost","root","");
mysql_select_db("bbs", $connect_id);
$query="select * from books order by bookid";
$rs=mysql_query($query,$connect_id);
$numfields=mysql_num_fields($rs);
$xmlfile="
";
$xmlfile.="
while($row=mysql_fetch_array($rs)){
for($i=0;$i<$numfields;$i++){
$fieldname=mysql_field_name($rs,$i );
$xmlfile.="<" . $fieldname . ">" . $row[$i] . "" . $fieldname . ">
";
}
}
mysql_free_result($rs);
mysql_close($connect_id);
$xmlfile.="
$fp=fopen("xmldoc/xmldoc.xml","w");
if(fwrite($fp,$xmlfile)){
echo "Write file successfully!";
}
else{
echo "Failed to write file!";
}
?>
This is the source code that takes data from XML and converts it into HTML. .
class xml{
var $parser;