php 靜態(tài)頁面中顯示動態(tài)內(nèi)容
更新時間:2009年08月14日 17:04:25 作者:
靜態(tài)頁面中顯示動態(tài)內(nèi)容,一些網(wǎng)站的qq在線狀態(tài),還有購物車用的是這個方法
最近在做一個站點時,需要生成靜態(tài)頁面,但是生成的靜態(tài)頁面中有些內(nèi)容是需要動態(tài)獲取的,怎不能每天生成一下吧。。
最后上網(wǎng)查了一下,再加上個要總結(jié),呵。。。。終于實現(xiàn)了。。發(fā)出來,大家一起研究。。呵。。。
<span class="STYLE1">應(yīng)用一</span>:文章計數(shù),獲取動態(tài)內(nèi)容
計數(shù)頁: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?>");
靜態(tài)頁面mk.html中加入即可
<script src="count.php?id=<?=$id?>"></script>
切記:頁面路徑,生成靜態(tài)后計數(shù)文件路徑會變。。
<span class="STYLE1">應(yīng)用二</span>:獲取此頁面中一些動態(tài)信息,例如相關(guān)文章之類
同樣,靜態(tài)頁面中的鏈接還是此種形式
<script src="read.php?cid=<?=$A['code']?>"></script>
read.php里內(nèi)容如下:
<?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>
最后上網(wǎng)查了一下,再加上個要總結(jié),呵。。。。終于實現(xiàn)了。。發(fā)出來,大家一起研究。。呵。。。
<span class="STYLE1">應(yīng)用一</span>:文章計數(shù),獲取動態(tài)內(nèi)容
計數(shù)頁:count.php
復(fù)制代碼 代碼如下:
<?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?>");
靜態(tài)頁面mk.html中加入即可
<script src="count.php?id=<?=$id?>"></script>
切記:頁面路徑,生成靜態(tài)后計數(shù)文件路徑會變。。
<span class="STYLE1">應(yīng)用二</span>:獲取此頁面中一些動態(tài)信息,例如相關(guān)文章之類
同樣,靜態(tài)頁面中的鏈接還是此種形式
復(fù)制代碼 代碼如下:
<script src="read.php?cid=<?=$A['code']?>"></script>
read.php里內(nèi)容如下:
復(fù)制代碼 代碼如下:
<?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:
復(fù)制代碼 代碼如下:
<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>
您可能感興趣的文章:
相關(guān)文章
php禁用cookie后session設(shè)置方法分析
這篇文章主要介紹了php禁用cookie后session設(shè)置方法,分析了php相關(guān)配置文件的功能與設(shè)置方法,具有一定參考借鑒價值,需要的朋友可以參考下2016-10-10PHP pthreads v3下worker和pool的使用方法示例
這篇文章主要介紹了PHP pthreads v3下worker和pool的使用方法,結(jié)合實例形式分析了PHP pthreads v3下worker和pool的基本功能、原理、使用方法及相關(guān)操作注意事項,需要的朋友可以參考下2020-02-02ThinkPHP使用心得分享-上傳類UploadFile的使用
ThinkPHP中的UploadFile類用于處理文件上傳,本文小總結(jié)了一下關(guān)于學(xué)習(xí)過程中對UploadFile類的使用方法。2014-05-05PHP數(shù)組無限分級數(shù)據(jù)的層級化處理代碼
在很多朋友寫無限級分類數(shù)據(jù)時都直接使用遞歸來操作,下面我來介紹一下關(guān)于PHP無限分級代碼優(yōu)化方法,有需要的朋友可參考一下2012-12-12批量獲取memcache值并按key的順序返回的實現(xiàn)代碼
一臺memcache時返回是正確的,在有多臺memcache時就無法一一對應(yīng)的按順序返回。2011-06-06