php 静态页面中显示动态内容

yipeiwu_com6年前PHP代码库
最近在做一个站点时,需要生成静态页面,但是生成的静态页面中有些内容是需要动态获取的,怎不能每天生成一下吧。。
最后上网查了一下,再加上个要总结,呵。。。。终于实现了。。发出来,大家一起研究。。呵。。。
<span class="STYLE1">应用一</span>:文章计数,获取动态内容
计数页:count.php
复制代码 代码如下:

<?php
require_once './global.php';
$DB->query("update ".$tablepre."teacher set views=views+1 where id='".$_GET['id']."'");
$hello=$DB->fetch_one_array("select * from ".$tablepre."teacher where id='".$_GET['id']."'");
$hcount=$hello['views'];
?>
document.write("<?=$hcount?>");

静态页面mk.html中加入即可
<script src="count.php?id=<?=$id?>"></script>
切记:页面路径,生成静态后计数文件路径会变。。
<span class="STYLE1">应用二</span>:获取此页面中一些动态信息,例如相关文章之类
同样,静态页面中的链接还是此种形式
复制代码 代码如下:

<script src="read.php?cid=<?=$A['code']?>"></script>

read.php里内容如下:
复制代码 代码如下:

<?php
$cid=$_GET['cid'];
?>
document.write("<TABLE cellSpacing=1 cellPadding=8 width=100% bgColor=#c4cbce border=0>");
document.write("<TR bgColor=#ffffff align=center>");
document.write("<TD width=33% align=center bgcolor=#ffffff>订单号</TD>");
document.write("<TD>年级科目</TD>");
document.write("<TD>时间</TD>");
document.write("</TR>");
<?php
$succquery=$DB->query("select * from ".$tablepre."test where cid='$cid'");
while($succ=$DB->fetch_array($succquery))
{
?>
document.write("<TR bgColor=#ffffff align=center>");
document.write("<TD><?=$succ['id']?></TD>");
document.write("<TD><?=$succ['city']?></TD>");
document.write("<TD><?=date('Y-m-d H:i:s',$succ['addtime'])?></TD>");
document.write("</TR>");
<?php
}
?>
document.write("</TABLE>");
document.write("<br>");

还有另外一种方法:
static side:
复制代码 代码如下:

<html><body>
<script>
function fill_in(html)
{
document.getElementById('into').innerHTML = html;
}
</script>
<div id="into"></div>
<iframe name="dynamic" src="dynamic.html" style="width:0px;height:0px:frame-border:none;display:none;"></iframe>
</body></html>
dynamic page:
<html><body>
<div id="content">fill in any thing that is dynamic without document.write()</div>
<script>
var html = document.getElementById('content').innerHTML;
parent.fill_in(html);
document.getElementById('content').innerHTML = "";
</script>
</body></html>

相关文章

PHP批量获取网页中所有固定种子链接的方法

本文实例讲述了PHP批量获取网页中所有固定种子链接的方法。分享给大家供大家参考,具体如下: 经常的下载链接比较多的时候,就像一次性将所有的链接添加到迅雷或者电炉,但是没有在这种选项,怎么...

解析thinkphp的左右值无限分类

以前一直使用父子无限分类,这种分类结构清晰,使用也简单。但若分类数量很大的话,在查询上性能不佳。比如在做导航菜单中,我要根据某一分类查询出整个分类树的话(祖辈)。性能消耗是非常大的,要么...

PHP大文件分块上传功能实例详解

本文实例讲述了PHP大文件分块上传功能。分享给大家供大家参考,具体如下: 前端代码 使用file.slice将文件进行分割,然后分别进行异步上传。 <!DOCTYPE html...

PHP和Shell实现检查SAMBA与NFS Server是否存在

通常会通过 /etc/fstab 来处理挂载的设置,然后再使用 mount -a 来重新确认挂载,最好在排程的程序用到挂载目录时也执行一次 mount -a,挂载目录在断线后是不会自动回...

简单实现php上传文件功能

本文实例为大家分享了php上传文件功能的具体代码,供大家参考,具体内容如下 html: <form action="upload_file.php" method="post"...