【www.gdgbn.com--mysql教程】

 代码如下

$con=mysql教程_connect("localhost","root","")or die("链接错误!!!");
mysql_select_db("message",$con)or die("数据库链接错误!!!");
mysql_query("set names "gbk"");
$sql=mysql_query("select * from message");

if($_post[button]){
while($row=mysql_fetch_array($sql)){
$path=$row[0].".html";
$user=$row[1];
$title=$row[2];
$content=$row[3];
$date=$row[4];

$fp=fopen("moban/html.html","r");
$str=fread($fp,filesize("./moban/html.html"));
$str=str_replace("{user}",$user,$str);
$str=str_replace("{title}",$title,$str);
$str=str_replace("{content}",$content,$str);
$str=str_replace("{date}",$date,$str);
fclose($fp);

$handle=fopen("news/".$path,"w");
fwrite($handle,$str);
fclose($handle);
echo "<script>alert("生成成功!!!");window.location.href="html.php";</script>";
}
}
?>




无标题文档



 


模板文件代码

 代码如下





无标题文档



 
    名称:
    {user}
 
 
    标题:
    {title}
 
 
    内容:
    {content}
 
 
    日期:
    {date}
 
 
   
   
 

删除html代码

 代码如下

$con=mysql_connect("localhost","root","")or die("链接错误!!!");
mysql_select_db("message",$con)or die("数据库链接错误!!!");
mysql_query("set names "gbk"");
$sql=mysql_query("select * from message");

if($_post[button]){
while($row=mysql_fetch_array($sql)){
$path=$row[0].".html";

 
  if(@unlink("news/".$path)){
  echo "<script>alert("删除成功!!!");window.location.href="unlink_html.php";</script>";
  }else{
  echo "<script>alert("无内容可以删除!!!");window.location.href="unlink_html.php";</script>";
  }
  }
}
?>


 

//数据库结构,用phpmyadmin导入就行了

 表的结构 `message`
--

create table `message` (
  `id` int(4) not null auto_increment,
  `user` varchar(20) not null,
  `title` varchar(100) not null,
  `content` text not null,
  `date` date not null,
  primary key  (`id`)
) engine=myisam  default charset=gbk auto_increment=3 ;

--
-- 导出表中的数据 `message`
--

insert into `message` (`id`, `user`, `title`, `content`, `date`) values
(1, "dfkk", "数据库信息生成静态页面", "www.111cn.net", "2010-02-12"),
(2, "dfkk", "数据库信息生成静态页面", "原理很简单", "2010-02-12");


自己写的,可通过按钮生成静态页面和删除已生成的静态页面。

moban存放模板文件夹(勿删)。

news生成静态页面文件夹(勿删)。


注意事项:phpmyadmin工具导入数据库文件message.sql。

本文来源:http://www.gdgbn.com/shujuku/25786/