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

2015-01-24信息快讯网

静态页面中显示动态内容,一些网站的qq在线状态,还有购物车用的是这个方法

最近在做一个站点时,需要生成静态页面,但是生成的静态页面中有些内容是需要动态获取的,怎不能每天生成一下吧。。
最后上网查了一下,再加上个要总结,呵。。。。终于实现了。。发出来,大家一起研究。。呵。。。
<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学习 变量使用总结
优化php效率,提高php性能的一些方法
php 代码优化之经典示例
php模拟asp中的XmlHttpRequest实现http请求的代码
用php的ob_start来生成静态页面的方法分析
php下删除一篇文章生成的多个静态页面
php抓取页面与代码解析 推荐
PHP定时自动生成静态HTML的实现代码
PHP zlib扩展实现页面GZIP压缩输出
php文章内容分页并生成相应的htm静态页面代码
php中static静态变量的使用方法详解
php 生成静态页面的办法与实现代码详细版
谈PHP生成静态页面分析 模板+缓存+写文件
PHP 实现多服务器共享 SESSION 数据
MayFish PHP的MVC架构的开发框架
最新的php 文件上传模型,支持多文件上传
PHP DataGrid 实现代码
PHP 执行系统外部命令 system() exec() passthru()
PHP 源代码分析 Zend HashTable详解第1/3页
php 生成WML页面方法详解
php 随机数的产生、页面跳转、件读写、文件重命名、switch语句
php 论坛采集程序 模拟登陆,抓取页面 实现代码
PHP 页面跳转到另一个页面的多种方法方法总结
php 404错误页面实现代码
php 静态化实现代码
php2html php生成静态页函数
方便实用的PHP生成静态页面类(非smarty)第1/2页
不用mod_rewrite直接用php实现伪静态化页面代码
PHP生成HTML静态页面实例代码
PHP伪静态页面函数附使用方法
生成静态页面的php函数,php爱好者站推荐
©2014-2024 dbsqp.com