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自动适应范围的分页代码
Aug 05 PHP
php 变量定义方法
Jun 14 PHP
在MongoDB中模拟Auto Increment的php代码
Mar 06 PHP
ThinkPHP使用smarty模板引擎的方法
Jul 01 PHP
制作安全性高的PHP网站的几个实用要点
Dec 30 PHP
Symfony2安装的方法(2种方法)
Feb 04 PHP
Yii列表定义与使用分页方法小结(3种方法)
Jul 15 PHP
Laravel5.5新特性之友好报错以及展示详解
Aug 13 PHP
浅析PHP数据导出知识点
Feb 17 PHP
PHP使用file_get_contents发送http请求功能简单示例
Apr 29 PHP
Laravel框架Auth用户认证操作实例分析
Sep 29 PHP
yii框架结合charjs实现统计30天数据的方法
Apr 04 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 curl_setopt 函数的相关应用及介绍
2013/06/17 PHP
PHP中spl_autoload_register函数的用法总结
2013/11/07 PHP
php数据库备份还原类分享
2014/03/20 PHP
PHP PDOStatement::getAttribute讲解
2019/02/01 PHP
php 使用expat方式解析xml文件操作示例
2019/11/26 PHP
如何实现浏览器上的右键菜单
2006/07/10 Javascript
基于jQuery的仿flash的广告轮播代码
2010/11/04 Javascript
jQuery cdn使用介绍
2013/05/08 Javascript
javascript-简单的计算器实现步骤分解(附图)
2013/05/30 Javascript
使用js在页面中绘制表格核心代码
2013/09/16 Javascript
JS实现点击颜色块切换指定区域背景颜色的方法
2015/02/25 Javascript
javascript包装对象实例分析
2015/03/27 Javascript
js识别uc浏览器的代码
2015/11/06 Javascript
JS Array创建及concat()split()slice()的使用方法
2016/06/03 Javascript
js HTML5上传示例代码完整版
2016/10/10 Javascript
angularJS利用ng-repeat遍历二维数组的实例代码
2017/06/03 Javascript
js 获取json数组里面数组的长度实例
2017/10/31 Javascript
vue引入axios同源跨域问题
2018/09/27 Javascript
js回文数的4种判断方法示例
2019/06/04 Javascript
vue中destroyed方法的使用说明
2020/07/21 Javascript
Python urllib模块urlopen()与urlretrieve()详解
2013/11/01 Python
Python 数值区间处理_对interval 库的快速入门详解
2018/11/16 Python
python plt可视化——打印特殊符号和制作图例代码
2020/04/17 Python
python3 使用openpyxl将mysql数据写入xlsx的操作
2020/05/15 Python
python中数字是否为可变类型
2020/07/08 Python
英国最大的婴儿监视器网上商店:Baby Monitors Direct
2018/04/24 全球购物
澳洲健康食品网上商店:Aussie Health Products
2018/06/15 全球购物
国家地理在线商店:Shop National Geographic
2018/06/30 全球购物
会计专业自我鉴定范文
2013/12/29 职场文书
大班亲子运动会方案
2014/06/10 职场文书
2014个人反腐倡廉思想汇报
2014/09/15 职场文书
2014年药剂科工作总结
2014/11/26 职场文书
2015年重阳节活动总结
2015/03/24 职场文书
2015年音乐教学工作总结
2015/07/22 职场文书
2016高考寄语集锦
2015/12/04 职场文书
python中sqllite插入numpy数组到数据库的实现方法
2021/06/21 Python