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

时间:2023-11-18 22:09:22 

最近在做一个站点时,需要生成静态页面,但是生成的静态页面中有些内容是需要动态获取的,怎不能每天生成一下吧。。
最后上网查了一下,再加上个要总结,呵。。。。终于实现了。。发出来,大家一起研究。。呵。。。
<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>
标签:静态页面,动态内容
0
投稿

猜你喜欢

  • PyQT5 QTableView显示绑定数据的实例详解

    2023-09-09 19:40:40
  • python小技巧——将变量保存在本地及读取

    2022-02-14 23:35:14
  • PHP中include和require的使用详解

    2023-10-22 03:57:03
  • Python Web框架之Django框架cookie和session用法分析

    2021-08-23 05:30:15
  • Python获取、格式化当前时间日期的方法

    2021-05-27 17:34:06
  • 远程登陆SQL Server 2014数据库的方法

    2024-01-28 03:39:01
  • js控制文本框禁止输入特殊字符详解

    2024-04-25 13:07:03
  • mysql 5.7.17 安装配置方法图文教程(CentOS7)

    2024-01-19 01:09:22
  • python中threading开启关闭线程操作

    2022-10-02 22:40:26
  • 基于PyQt5制作一个windows通知管理器

    2022-10-18 19:28:24
  • 解析SQL server与asp 互操作的时间处理

    2009-02-05 16:13:00
  • 带你了解python装饰器

    2023-08-26 23:10:57
  • Flaks基础之在URL中添加变量的实现详解

    2023-07-22 00:42:20
  • python交换两个变量的值方法

    2022-07-28 10:10:48
  • 在pyCharm中下载第三方库的方法

    2022-12-17 10:37:16
  • Python转换itertools.chain对象为数组的方法

    2022-10-27 08:38:16
  • Python详细讲解图像处理的而两种库OpenCV和Pillow

    2022-08-14 05:23:19
  • 解决pandas使用read_csv()读取文件遇到的问题

    2021-08-29 18:31:02
  • Python用requests-html爬取网页的实现

    2023-03-21 13:24:14
  • VSCODE配置Markdown及Markdown基础语法详解

    2021-10-02 10:21:20
  • asp之家 网络编程 m.aspxhome.com