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


Posted in PHP onAugust 14, 2009

最近在做一个站点时,需要生成静态页面,但是生成的静态页面中有些内容是需要动态获取的,怎不能每天生成一下吧。。
最后上网查了一下,再加上个要总结,呵。。。。终于实现了。。发出来,大家一起研究。。呵。。。
<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动态创建Flash动画
Oct 09 PHP
php中ob(Output Buffer 输出缓冲)函数使用方法
Jul 21 PHP
php正则表达式(regar expression)
Sep 10 PHP
PHP 面向对象程序设计(oop)学习笔记 (五) - PHP 命名空间
Jun 12 PHP
Yii 快速,安全,专业的PHP框架
Sep 03 PHP
项目中应用Redis+Php的场景
May 22 PHP
PHP MYSQL简易交互式站点开发
Dec 27 PHP
PHP从数组中删除元素的四种方法实例
May 12 PHP
老生常谈PHP面向对象之解释器模式
May 17 PHP
作为PHP程序员你要知道的另外一种日志
Jul 30 PHP
php写入文件不覆盖的实例讲解
Sep 17 PHP
PHP命令行与定时任务
Apr 01 PHP
MayFish PHP的MVC架构的开发框架
Aug 13 #PHP
最新的php 文件上传模型,支持多文件上传
Aug 13 #PHP
PHP DataGrid 实现代码
Aug 12 #PHP
PHP 执行系统外部命令 system() exec() passthru()
Aug 11 #PHP
php empty函数 使用说明
Aug 10 #PHP
php 取得瑞年与平年的天数的代码
Aug 10 #PHP
php 生成WML页面方法详解
Aug 09 #PHP
You might like
PHP JSON格式数据交互实例代码详解
2011/01/13 PHP
简单谈谈favicon
2015/06/10 PHP
PHP指定截取字符串中的中英文或数字字符的实例分享
2016/03/18 PHP
PHP类的特性实例分析
2016/09/28 PHP
Docker搭建自己的PHP开发环境
2018/02/24 PHP
PHP随机数函数rand()与mt_rand()的讲解
2019/03/25 PHP
CL vs ForZe BO5 第二场 2.13
2021/03/10 DOTA
jQuery点击后一组图片左右滑动的实现代码
2012/08/16 Javascript
jsp网页搜索结果中实现选中一行使其高亮
2014/02/17 Javascript
js制作简易年历完整实例
2015/01/28 Javascript
JavaScript实现横向滑出的多级菜单效果
2015/10/09 Javascript
微信小程序 Record API详解及实例代码
2016/09/30 Javascript
javascript创建对象的3种方法
2016/11/02 Javascript
js编写的treeview使用方法
2016/11/11 Javascript
关于Stream和Buffer的相互转换详解
2017/07/26 Javascript
js canvas实现简单的图像扩散效果
2020/06/28 Javascript
javascript回调函数详解
2018/02/06 Javascript
vue移动端实现下拉刷新
2018/04/22 Javascript
详解如何使用webpack打包JS
2018/06/21 Javascript
[02:40]DOTA2英雄基础教程 先知
2013/11/29 DOTA
[01:13:51]TNC vs Serenity 2018国际邀请赛小组赛BO2 第二场 8.18
2018/08/19 DOTA
探究Python中isalnum()方法的使用
2015/05/18 Python
在Python的Django框架中调用方法和处理无效变量
2015/07/15 Python
巧用python和libnmapd,提取Nmap扫描结果
2016/08/23 Python
浅谈Pycharm调用同级目录下的py脚本bug
2018/12/03 Python
Python设计模式之享元模式原理与用法实例分析
2019/01/11 Python
Python3解释器知识点总结
2019/02/19 Python
用Python实现将一张图片分成9宫格的示例
2019/07/05 Python
Python控制台输出时刷新当前行内容而不是输出新行的实现
2020/02/21 Python
css3进行截取替代js的substring
2013/09/02 HTML / CSS
乌克兰品牌化妆品和香水在线商店:Bomond
2020/01/14 全球购物
求职推荐信
2013/10/28 职场文书
集体婚礼证婚词
2014/01/13 职场文书
小班开学寄语
2014/04/04 职场文书
个性婚礼策划方案
2014/05/17 职场文书
python四种出行路线规划的实现
2021/06/23 Python