Copy codeThe Code is as follows:
<? Php
/*
Author: www.5dkx.com
Done: Generate html documents
Date: 2009-10-27
*/
Require_once ("conn. php ");
If ($ _ GET ['all'])
{
/* Obtain database records to generate html files with a file name */
$ Sqlquery = "select * from $ tbname ";
$ Result = mysql_query ($ sqlquery, $ conn) or die ("query failed! ");
$ Fp = fopen ("./template/article.html", r );
$ Fpcontent = fread ($ fp, filesize ("./template/article.html "));
Fclose ($ fp );
/* Write File */
While ($ row = mysql_fetch_array ($ result ))
{
$ Fpcontent = str_replace ("{thetitle}", $ row ['title'], $ fpcontent );
$ Fpcontent = str_replace ("{chatitle}", $ row ['title'], $ fpcontent );
$ Fpcontent = str_replace ("{bookcontent}", $ row ['content'], $ fpcontent );
$ Fp = fopen ("./html/". $ row ['id']. ". html", w) or die ("Opening and writing files failed! ");
Fwrite ($ fp, $ fpcontent) or die ("failed to write file! ");
}
Echo "<script language = \" javascript \ "> alert ('Update all '); </script> ";
}
If ($ _ GET ['part'])
{
/* Obtain the ID of the last record to generate an html file with a file name */
$ Sqlquery = "select * from $ tbname order by id desc limit 1 ";
$ Result = mysql_query ($ sqlquery, $ conn) or die ("query failed! ");
$ Row = mysql_fetch_array ($ result );
$ Fp = fopen ("./template/article.html", r );
$ Fpcontent = fread ($ fp, filesize ("./template/article.html "));
Fclose ($ fp );
$ Fpcontent = str_replace ("{thetitle}", $ row ['title'], $ fpcontent );
$ Fpcontent = str_replace ("{chatitle}", $ row ['title'], $ fpcontent );
$ Fpcontent = str_replace ("{bookcontent}", $ row ['content'], $ fpcontent );
$ Fp = fopen ("./html/". $ row ['id']. ". html", w) or die ("Opening and writing files failed! ");
Fwrite ($ fp, $ fpcontent) or die ("failed to write file! ");
Echo "<script language = \" javascript \ "> alert ('partially updated successfully! '); </Script> ";
}
?>
<Html>
<Head>
<Title> Generate an html document </title>
<Script language = "javascript">
Function btnsubmit (form)
{
Theform. submit ();
}
</Script>
</Head>
<Body>
<?
Echo "<a href =? All = 111> Update all </a> <br> <a href =? Part = 111> partial update </a> ";
?>
</Body>
</Html>