php静态页面中显示动态内容
2023-06-13 09:14:12 时间
最近在做一个站点时,需要生成静态页面,但是生成的静态页面中有些内容是需要动态获取的,怎不能每天生成一下吧。。
最后上网查了一下,再加上个要总结,呵。。。。终于实现了。。发出来,大家一起研究。。呵。。。
<spanclass="STYLE1">应用一</span>:文章计数,获取动态内容
计数页:count.php
复制代码代码如下:
最后上网查了一下,再加上个要总结,呵。。。。终于实现了。。发出来,大家一起研究。。呵。。。
<spanclass="STYLE1">应用一</span>:文章计数,获取动态内容
计数页:count.php
<?php
require_once"./global.php";
$DB->query("update".$tablepre."teachersetviews=views+1whereid="".$_GET["id"].""");
$hello=$DB->fetch_one_array("select*from".$tablepre."teacherwhereid="".$_GET["id"].""");
$hcount=$hello["views"];
?>
document.write("<?=$hcount?>");
静态页面mk.html中加入即可
<scriptsrc="count.php?id=<?=$id?>"></script>
切记:页面路径,生成静态后计数文件路径会变。。
<spanclass="STYLE1">应用二</span>:获取此页面中一些动态信息,例如相关文章之类
同样,静态页面中的链接还是此种形式
<scriptsrc="read.php?cid=<?=$A["code"]?>"></script>
read.php里内容如下:
<?php
$cid=$_GET["cid"];
?>
document.write("<TABLEcellSpacing=1cellPadding=8width=100%bgColor=#c4cbceborder=0>");
document.write("<TRbgColor=#ffffffalign=center>");
document.write("<TDwidth=33%align=centerbgcolor=#ffffff>订单号</TD>");
document.write("<TD>年级科目</TD>");
document.write("<TD>时间</TD>");
document.write("</TR>");
<?php
$succquery=$DB->query("select*from".$tablepre."testwherecid="$cid"");
while($succ=$DB->fetch_array($succquery))
{
?>
document.write("<TRbgColor=#ffffffalign=center>");
document.write("<TD><?=$succ["id"]?></TD>");
document.write("<TD><?=$succ["city"]?></TD>");
document.write("<TD><?=date("Y-m-dH:i:s",$succ["addtime"])?></TD>");
document.write("</TR>");
<?php
}
?>
document.write("</TABLE>");
document.write("<br>");
还有另外一种方法:
staticside:
<html><body>
<script>
functionfill_in(html)
{
document.getElementById("into").innerHTML=html;
}
</script>
<divid="into"></div>
<iframename="dynamic"src="dynamic.html"style="width:0px;height:0px:frame-border:none;display:none;"></iframe>
</body></html>
dynamicpage:
<html><body>
<divid="content">fillinanythingthatisdynamicwithoutdocument.write()</div>
<script>
varhtml=document.getElementById("content").innerHTML;
parent.fill_in(html);
document.getElementById("content").innerHTML="";
</script>
</body></html>
相关文章
- PHP各环境下的伪静态配置,可直接用
- 攻防世界的Web_php_wrong_nginx_config实战题目
- 页面Linux下PHP页面显示问题排查(linux不能显示php)
- PHP在Linux上安装:轻松快捷(php安装包linux)
- 深入学习:PHP如何配置MySQL(php如何配置mysql)
- [图]macOS Monterey不再内置PHP 需开发人员自行安装
- 程序快速学会在Linux中执行PHP程序(linux执行php)
- 使用PHP和MySQL创建数据表(phpmysql创建表)
- 轻松实现PHP操控MySQL语句(php执行mysql语句)
- 从MySQL到PHP:展示表格数据(php显示mysql表)
- PHP中的Redis类:快速高效地管理数据(redis类php)
- PHP开发者必须了解的Linux常识(php开发linux)
- PHP实现Object Oriented Stye封装MySQL类(php封装mysql类)
- 高效实现消息处理: Redis队列与PHP的并发技巧(redis队列并发php)
- 使用PHP和MySQL研究论文(php mysql 论文)
- MySQL与PHP开发之旅(mysql与php书籍)
- PHP操作MySQL数据库,轻松获取数据。(php访问mysql数据库)
- PHP.MVC的模板标签系统(三)
- PHP生成静态页
- PHP伪静态页面函数附使用方法
- 不用mod_rewrite直接用php实现伪静态化页面代码
- php静态变量的初始化
- PHP新手NOTICE错误常见解决方法
- PHP对象Object的概念介绍
- 关于PHP结束标签的使用细节探讨及联想
- 基于php伪静态的实现详细介绍
- php字符串压缩方法比较示例
- PHP中auto_prepend_file与auto_append_file用法实例分析