<?php
include_once('connection.php');
global $DB_Document_Read;
$sql="select name from `base_keyword` where state='1' and type=148";
$res=$DB_Document_Read->get_results($sql);
foreach ($res as $k=>$v){
$name = $v[name]; //栏目名称, 可以能有很多条
$fs= fopen("left.inc.htm","r"); //打开定义好的模板文件
$fread =fread($fs,filesize("left.inc.htm")); //读取模板文件
$path="column/"; //生成页面存放的路径
if (!file_exists($path)) { //如果不存在则创立
mkdir($path);
}
/*定义一个显示的页面*/
$path=$path.'column_cid'.'.html';
$str=str_replace("<%name%>",$name,$fread); //值替换
$handle=fopen($path,"w"); //以写的形式打开定义好的页面
fwrite($handle,$str); //写值
fclose($handle); //关闭
echo "生成成功!";
}
?>
它的作用是通过动态页面生成栏目的静态页面,但有一个错误是,当程序运行的时候,后面的数据把前面的数据覆盖掉了,
最后只在模板页面只显示最后一条栏目数据的数据,大家能帮助我改下吗?在生成静态页面的时候,能在栏目中显示多条数据?
及: 栏目一、栏目二
<?php
include_once('connection.php');
global $DB_Document_Read;
$sql="select name from `base_keyword` where state='1' and type=148";
$res=$DB_Document_Read->get_results($sql);$path="column/"; //生成页面存放的路径
if (!file_exists($path)) { //如果不存在则创立
mkdir($path);
}
/*定义一个显示的页面*/
$path=$path.'column_cid'.'.html';
$handle=fopen($path,"w"); //以写的形式打开定义好的页面foreach ($res as $k=>$v){
$name = $v[name]; //栏目名称, 可以能有很多条
$fs= fopen("left.inc.htm","r"); //打开定义好的模板文件
$fread =fread($fs,filesize("left.inc.htm")); //读取模板文件
$str=str_replace("<%name%>",$name,$fread); //值替换
fwrite($handle,$str); //写值
}
fclose($handle); //关闭
echo "生成成功!";
?>
echo "Hello World!";
$content = ob_get_contents();//取得php页面输出的全部内容
$fp = fopen("0001.html", "w");
fwrite($fp, $content);
fclose($fp);