这是在看太平洋网的评论时看到的,太平洋网是用jsp做为后台语言,用来产生xml文件.然后在把数据绑定到html上的.我就用php也做了一个以下是源文件.
—————–xml.htm——————
<!doctype html public “-//w3c//dtd html 4.01 transitional//en” “/d/file/titlepic/loo.dtd& /><html>
<head>
<meta http-equiv=”content-type” content=”text/html; chart=gb2312″>
<title>xml</title>我要飞的很高;
</head>
<body>
<xml id=”shoplist” src=”xml.php”></xml>
<script>
function jump(form)
{
if (form.pagenum.value>parint(pagecount.innerhtml)) return fal;
if (form.pagesize.value>parint(recordcount.innerhtml)) return fal;
shoplist.src=”xml.php?pageno=”+form.pagenum.value+”&pagesize=”+form.pagesize.value+”&time=”+(new date()).gettime();
}
function pagecount_onpropertychange(form)
{
if (form.pagenum.value>parint(pagecount.innerhtml)) form.pagenum.value=parint(pagecount.innerhtml);
if (form.pagesize.value>parint(recordcount.innerhtml)) form.pagesize.value=parint(recordcount.innerhtml);
if(form.pagenum.value==1)
{
form.firstpage.disabled=true;
form.previouspage.disabled=true;
}
el
{
form.firstpage.disabled=fal;
form.previouspage.disabled=fal;
}
if(form.pagenum.value==form.pagecount.value)
{
form.nextpage.disabled=true;
form.lastpage.disabled=true;
}
el
{
form.nextpage.disabled=fal;
form.lastpage.disabled=fal;
}
}
</script>
<table width=”100%” height=”25″ border=”0″ cellpadding=”2″ cellspacing=”1″ id=”shoptbl” datasrc=#shoplist datafld=商铺>
<thead>
<tr>
<td height=”25″ colspan=”4″><span class=”shop_3d_text”>店铺列表</span></td>
</tr>
<tr>
<td width=”30%”>商铺名称</td>
<td width=”20%”>经营者</td>
<td width=”20%”>店铺级别</td>
<td width=”30%”>店铺简介</td>
</tr>
</thead>
<tbody>
<tr style=”background-color:expression(rowindex%2==1?’#efefef’:’#ffffff’)”>
<td><a datafld=”连接地址”><span datafld=”名称”>名称</span></a></td>
<td><span datafld=”经营人”>经营人</span></td>
<td><span datafld=”级别”>级别</span></td>
<td><span datafld=”简介”>简介</span></td>
</tr>
</tbody>
</table>
<form return onsubmit=”jump(this);return fal”>
<div align=”right”>
每页显示
<input name=pagesize datasrc=#shoplist datafld=页大小 size=2>条,
<input type=submit value=”” style=”width:0″>
共<span id=”pagecount” datasrc=#shoplist datafld=页数量></span>页
<span id=”recordcount” datasrc=#shoplist datafld=数量 ></span>条
<input name=firstpage type=submit value=首页 onclick=”pagenum.value=1″>
<input name=previouspage type=submit value=上页 onclick=”pagenum.value=pagenum.value-1″>
第<input name=pagenum datasrc=#shoplist datafld=页号码 size=2>页
<input name=nextpage type=submit value=下页 onclick=”pagenum.value=(pagenum.value-0)+1″>
<input name=lastpage type=submit value=尾页 onclick=”pagenum.value=pagecount.value” >
<input name=pagecount type=hidden datasrc=#shoplist datafld=页数量 onpropertychange=”pagecount_onpropertychange(form)”>
</div> </form>
</body>
</html>
—————–xml.php——————
<?php
//require_once “source/global.php”;
function getvars($get_vars, $post_vars) {
$i = count($get_vars);
$j = count($post_vars);
if ($i > 0 && $j > 0 ) {
while(list($key, $val) = each($get_vars)) {
$vars[$key] = $val;
}
while(list($key2, $val2) = each($post_vars)) {
$vars[$key2] = $val2;
}
} elif ($i > 0) {
while(list($key, $val) = each($get_vars)) {
$vars[$key] = $val;
}
} elif ($j > 0) {
while(list($key2, $val2) = each($post_vars)) {
$vars[$key2] = $val2;
}
} el {
$vars = array();
}
return $vars;
}
$vars = getvars($http_get_vars, $http_post_vars);
//class shoplist_res extends iglobal{
class shoplist_res{
function shoplist_res($vars,$cookie){
//$this->iglobal($vars,$cookie);
$this->output($vars,$cookie);
}
//function _shoplist_res(){
//$this->db->clo();
//}
function output($vars,$cookie){
/*$strquery = “lect count(*) as rc from “.$this->db_c->db_pre.”pshop order by id desc”;
$this->db->query($strquery);
$recordcount = $this->db->assoc();
$recordcount = $recordcount[‘rc’];
@$this->db->freeresult();*/
$recordcount = 25;
if (empty($vars[‘pageno’])) $vars[‘pageno’]= 1;
if (empty($vars[‘pagesize’])) $vars[‘pagesize’]= 10;
$pagecount = ceil($recordcount/$vars[‘pagesize’]);
if ($vars[‘pagesize’]>$recordcount) $vars[‘pagesize’]=$recordcount;
if ($vars[‘pageno’]>$pagecount) $vars[‘pageno’]=$pagecount;
$xmlstr.= “<?xml version=\”1.0\” encoding=\”gbk\” ?>”.”\n”;
$xmlstr.= “<商铺列表>”.”\n”;
$xmlstr.= “\t<翻页工具 pageno=\””.$vars[‘pageno’].”\” pagesize=\””.$vars[‘pagesize’].”\” total=\””.$recordcount.”\”></翻页工具>超市管理”.”\n”;
$xmlstr.= “\t<页号码>”.$vars[‘pageno’].”</页号码>”.”\n”;
$xmlstr.= “\t<页大小>”.$vars[‘pagesize’].”</页大小>”.”\n”;
$xmlstr.= “\t<数量>”.$recordcount.”</数量>”.”\n”;
$xmlstr.= “\t<页数量>”.$pagecount.”</页数量>”.”\n”;
//$strquery = “lect t1.*,t2.* from “.$this->db_c->db_pre.”pshop as t1,”.$this->db_c->db_pre.”shoptype as t2 where t1.typenum=t2.typenum order by id desc “
//.”limit “.($vars[‘pageno’]-1)*$vars[‘pagesize’].”,”.$vars[‘pagesize’];
//die($strquery);
//$this->db->query($strquery);
/*while($result = $this->db->assoc()){
$xmlstr.= “\t”.”\n”;
$xmlstr.相对论的基本原理= “\t<商铺>”.”\n”;
$xmlstr.= “\t\t<名称><![cdata[“.$result[‘shopname’].”]]></名称>”.”\n”;
$xmlstr.= “\t\t<经营人><![cdata[“.$result[‘shopmaster’].”]]></经营人>”.”\n”;
$xmlstr.= “\t\t<级别><![cdata[“.$result[‘shoptype’].”]]></级别>”.”\n”;
$xmlstr.= “\t\t<简介><![cdata[“.$result[‘shopintro’].”]]></简介>”.”\n”;
$xmlstr.= “\t\t<连接地址><![cdata[personal_shop.php?id=”.$result[‘id’].”]]></连接地址>”.”\n”;
$xmlstr.= “\t</商铺>”.”\n”;
}*/
$sc= $vars[‘pageno’]*$vars[‘pagesize’];
if ($sc>$recordcount) $sc = $recordcount;
for($i=($vars[‘pageno’]-1)*$vars[‘pagesize’];$i<$sc;$i++){
$xmlstr.= “\t”.”\n”;
$xmlstr.= “\t<商铺>”.”\n”;
$xmlstr.= “\t\t<名称><![cdata[这是名称:”.$i.”]]></名称>”.”\n”;
$xmlstr.= “\t\t<经营人><![cdata[庆五一诗歌这是经营人:”.$i.”]]></经营人>”.”\n”;
$xmlstr.= “\t\t<级别><![cdata[这是级别:”.$i.”]]></级别>”.”\n”;
$xmlstr.= “\t\t<简介><![cdata[这是简介:”.$i.”]]></简介>”.”\n”;
$xmlstr.= “\t\t<连接地址><![cdata[personal_shop.php?id=”.$i.”]]></连接地址>”.”\n”;
$xmlstr.= “\t</商铺>”.”\n”;
}
$xmlstr.= “</商铺列表>”.”\n”;
header(“content-type: text/xml\n\n”);
echo $xmlstr;
}
}
$shoplist = new shoplist_res($vars,$http_cookie_vars);
//$shoplist->_shoplist_res();
unt($st被录取hoplist);
?>
以上的php,注释的是我连接数据库取得的数据,既然放上来测试,也没有数据库连接,所以改了一下.偶也是刚接解xml不久,很多地方还是不很懂.见笑了……
本文发布于:2023-04-06 07:24:54,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/24803faa79f0ea105e04bcab00e0996b.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:xml+php动态载入与分页.doc
本文 PDF 下载地址:xml+php动态载入与分页.pdf
留言与评论(共有 0 条评论) |