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自动注册登录验证机制实现代码
Dec 20 PHP
PHP遍历数组的几种方法
Mar 22 PHP
php判断上传的Excel文件中是否有图片及PHPExcel库认识
Jan 11 PHP
解析VS2010利用VS.PHP插件调试PHP的方法
Jul 19 PHP
实现获取http内容的php函数分享
Feb 16 PHP
php示例详解Constructor Prototype Pattern 原型模式
Oct 15 PHP
PHP动态地创建属性和方法, 对象的复制, 对象的比较,加载指定的文件,自动加载类文件,命名空间
May 06 PHP
php+MySql实现登录系统与输出浏览者信息功能
Jul 01 PHP
PHP 用session与gd库实现简单验证码生成与验证的类方法
Nov 15 PHP
PHP操作redis实现的分页列表,新增,删除功能封装类与用法示例
Aug 04 PHP
PHP实现数据四舍五入的方法小结【4种方法】
Mar 27 PHP
PHP中有关长整数的一些操作教程
Sep 11 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入门学习知识点四 PHP正则表达式基本应用
2011/07/14 PHP
解析如何去掉CodeIgniter URL中的index.php
2013/06/25 PHP
使用淘宝IP库获取用户ip地理位置
2013/10/27 PHP
php实现将任意进制数转换成10进制的方法
2015/04/17 PHP
详解PHP中mb_strpos的使用
2018/02/04 PHP
超简单的jquery的AJAX用法
2010/05/10 Javascript
JS中confirm,alert,prompt函数区别分析
2011/01/17 Javascript
JavaScript输出当前时间Unix时间戳的方法
2015/04/06 Javascript
javascript中Date format(js日期格式化)方法小结
2015/12/17 Javascript
Nodejs进阶:express+session实现简易登录身份认证
2017/04/24 NodeJs
jQuery tip提示插件(实例分享)
2017/04/28 jQuery
产制造追溯系统之通过微信小程序实现移动端报表平台
2019/06/03 Javascript
微信小程序实现订单倒计时
2020/11/01 Javascript
微信小程序中为什么使用var that=this
2019/08/27 Javascript
JavaScript实现PC端四格密码输入框功能
2020/02/19 Javascript
elementui更改el-dialog关闭按钮的图标d的示例代码
2020/08/04 Javascript
js实现弹幕墙效果
2020/12/10 Javascript
Python探索之ModelForm代码详解
2017/10/26 Python
python中is与双等于号“==”的区别示例详解
2017/11/21 Python
Python 函数基础知识汇总
2018/03/09 Python
python 读取修改pcap包的例子
2019/07/23 Python
Django应用程序入口WSGIHandler源码解析
2019/08/05 Python
Flask 上传自定义头像的实例详解
2020/01/09 Python
Django ForeignKey与数据库的FOREIGN KEY约束详解
2020/05/20 Python
Python学习之time模块的基本使用
2021/01/17 Python
python 基于pygame实现俄罗斯方块
2021/03/02 Python
Bally美国官网:经典瑞士鞋履、手袋及配饰奢侈品牌
2018/05/18 全球购物
师范大学毕业自我鉴定
2013/11/21 职场文书
违反学校规定检讨书
2014/01/18 职场文书
五好文明家庭事迹材料
2014/12/20 职场文书
工作检讨书怎么写
2015/01/23 职场文书
工作失误检讨书
2015/01/26 职场文书
区域销售经理岗位职责
2015/04/02 职场文书
2015年销售员工作总结范文
2015/04/07 职场文书
长江七号观后感
2015/06/11 职场文书
校运会加油稿大全
2015/07/22 职场文书