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

yipeiwu_com5年前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 strripos函数用法总结

php strripos()函数 语法 作用:寻找某字符串中某字符最后出现的位置,不区分大小写 语法: strripos(string,find,start) 参数: string...

PHP生成静态页面详解

一,PHP脚本与动态页面。    PHP脚本是一种服务器端脚本程序,可通过嵌入等方  法与HTML文件混合,也可以类,函数封装等形式,以模板的方式对用户请求进行处理。无论以何种方式...

几款免费开源的不用数据库的php的cms

1、MuCMS一个小型,平台独立的内容管理系统适用于非交互式网站(网站只发布信息)。它对系统要求非常低,只需要Apache+PHP。没有使用数据库。它具有安全,快速,易用等特点。官方网站...

php提高网站效率的技巧

程序员在编写程序时,总是想要使自己的程序占用资源最小,运行速度更快,代码量更少。往往我们在追求这些的同时却失去了很多东西。优化的目的是花最少的代价换来最快的运行速度与最容易维护的代码。以...

详解WordPress中添加和执行动作的函数使用方法

add_action()(添加动作) add_action() 函数用来挂载一个函数到动作钩子上。 用法 add_action( $tag, $function_to_add, $p...