mysql制作html静态网页6_将数据库中的所有内容生成html静态页面的代码
將數據庫中的所有內容生成html靜態頁的代碼,比較簡單了,有需要的朋友可以參考下。
復制代碼 代碼如下:
require_once("conn.php");
if($_GET['all'])
{
/*獲取數據庫記錄,以便于生成html文件有個文件名*/
$sqlquery = "select * from $tbname";
$result = mysql_query($sqlquery,$conn)or die("查詢失敗!");
$fp = fopen("./template/article.html",r);
$fpcontent = fread($fp,filesize("./template/article.html"));
fclose($fp);
/*寫入文件*/
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("打開寫入文件失敗!");
fwrite($fp,$fpcontent)or die("寫入文件失敗!");
}
echo "";
}
if($_GET['part'])
{
/*獲取最后一條記錄的ID,便于生成html文件有個文件名*/
$sqlquery = "select * from $tbname order by id desc limit 1";
$result = mysql_query($sqlquery,$conn)or die("查詢失敗!");
$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("打開寫入文件失敗!");
fwrite($fp,$fpcontent)or die("寫入文件失敗!");
echo "";
}
?>
生成htmlfunction btnsubmit(form)
{
theform.submit();
}
echo "全部更新部分更新";
?>
總結
以上是生活随笔為你收集整理的mysql制作html静态网页6_将数据库中的所有内容生成html静态页面的代码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: centos mysql-5.5.20_
- 下一篇: python stdout stderr