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 相关文章推荐
编译问题
Oct 09 PHP
php将数据库中所有内容生成静态html文档的代码
Apr 12 PHP
PHP中数字检测is_numeric与ctype_digit的区别介绍
Oct 04 PHP
destoon实现调用自增数字从1开始的方法
Aug 21 PHP
php计算2个日期的差值函数分享
Feb 02 PHP
php可应用于面包屑导航的迭代寻找家谱树实现方法
Feb 02 PHP
PHP文件操作方法汇总
Jul 01 PHP
PHP整合七牛实现上传文件
Jul 03 PHP
深入浅析Yii admin的权限控制
Aug 31 PHP
PHP工厂模式的日常使用
Mar 20 PHP
TP5框架页面跳转样式操作示例
Apr 05 PHP
PHP7 list() 函数修改
Mar 09 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
CI框架中site_url()和base_url()的区别
2015/01/07 PHP
PHP模板引擎Smarty中的保留变量用法分析
2016/04/11 PHP
iis6手工创建网站后无法运行php脚本的解决方法
2017/06/08 PHP
jqgrid 编辑添加功能详细解析
2013/11/08 Javascript
Javascript学习笔记之函数篇(六) : 作用域与命名空间
2014/11/23 Javascript
jQuery插件实现大图全屏图片相册
2015/03/14 Javascript
JavaScript DOM事件(笔记)
2015/04/08 Javascript
实例详解JavaScript获取链接参数的方法
2016/01/01 Javascript
Bootstrap中的fileinput 多图片上传及编辑功能
2016/09/05 Javascript
Bootstrap Table表格一直加载(load)不了数据的快速解决方法
2016/09/17 Javascript
angularJS+requireJS实现controller及directive的按需加载示例
2017/02/20 Javascript
js 获取html5的data属性实现方法
2017/07/28 Javascript
浅谈MUI框架中加载外部网页或服务器数据的方法
2018/01/31 Javascript
微信小程序踩坑记录之解决tabBar.list[3].selectedIconPath大小超过40kb
2018/07/04 Javascript
jquery将信息遍历到界面上实例代码
2020/01/21 jQuery
echarts 使用formatter 修改鼠标悬浮事件信息操作
2020/07/20 Javascript
js 函数性能比较方法
2020/08/24 Javascript
js实现随机点名功能
2020/12/23 Javascript
十个Python程序员易犯的错误
2015/12/15 Python
Python字典操作详细介绍及字典内建方法分享
2018/01/04 Python
Python设计模式之中介模式简单示例
2018/01/09 Python
python+selenium 鼠标事件操作方法
2019/08/24 Python
浅析使用Python搭建http服务器
2019/10/27 Python
Python如何爬取qq音乐歌词到本地
2020/06/01 Python
Python3爬虫中Selenium的用法详解
2020/07/10 Python
VSCODE配置Markdown及Markdown基础语法详解
2021/01/19 Python
稀有和绝版书籍:Biblio.com
2017/02/02 全球购物
详解如何解决使用JSON.stringify时遇到的循环引用问题
2021/03/23 Javascript
保护环境倡议书300字
2014/05/19 职场文书
公安机关党的群众路线教育实践活动剖析材料
2014/10/10 职场文书
党的群众路线教育实践活动批评与自我批评范文
2014/10/16 职场文书
项目合作意向书
2015/05/08 职场文书
郭明义观后感
2015/06/08 职场文书
毕业典礼致辞
2015/07/29 职场文书
pytorch中[..., 0]的用法说明
2021/05/20 Python
python垃圾回收机制原理分析
2022/04/13 Python