xml+php Dynamic Loading and paging
Last Update:2017-02-28
Source: Internet
Author: User
xml| Dynamic | Pagination This is seen in the comments of the Pacific Network, the Pacific network is using JSP as a background language, used to produce XML files. And then bind the data to the HTML. I did it in PHP. The following is a source file.
-----------------xml.htm------------------
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title>xml</title>
<body>
<xml id= "shoplist" src= "xml.php" ></xml>
<script>
function jump (form)
{
if (Form.pagenum.value>parseint (pagecount.innerhtml)) return false;
if (Form.pagesize.value>parseint (recordcount.innerhtml)) return false;
Shoplist.src= "xml.php?pageno=" +form.pagenum.value+ "&pagesize=" +form.pagesize.value+ "&time=" + (new Date () ). GetTime ();
}
function Pagecount_onpropertychange (form)
{
if (Form.pagenum.value>parseint (pagecount.innerhtml)) Form.pagenum.value=parseint (PageCount.innerHTML);
if (Form.pagesize.value>parseint (recordcount.innerhtml)) Form.pagesize.value=parseint (RecordCount.innerHTML);
if (form.pagenum.value==1)
{
Form.firstpage.disabled=true;
Form.previouspage.disabled=true;
}
Else
{
Form.firstpage.disabled=false;
Form.previouspage.disabled=false;
}
if (Form.pagenum.value==form.pagecount.value)
{
Form.nextpage.disabled=true;
Form.lastpage.disabled=true;
}
Else
{
Form.nextpage.disabled=false;
Form.lastpage.disabled=false;
}
}
</script>
<table width= "100%" height= "border=" 0 "cellpadding=" 2 "cellspacing=" 1 "id=" Shoptbl "datasrc= #ShopList datafld= Shop >
<thead>
<tr>
<TD height= "colspan=" 4 "><span class=" Shop_3d_text "> Store list </span></td>
</tr>
<tr>
<TD width= "30%" > Shop name </td>
<TD width= "20%" > Operator </td>
<TD width= "20%" > Shop level </td>
<TD width= "30%" > Shop profile </td>
</tr>
</thead>
<tbody>
<tr style= "background-color:expression (rowindex%2==1?") #EFEFEF ': ' #FFFFFF ') >
<td><a datafld= "Connection address" ><span datafld= "name" > Name </span></a></td>
<td><span datafld= "operator" > operator </span></td>
<td><span datafld= "Level" > Level </span></td>
<td><span datafld= "Introduction" > Introduction </span></td>
</tr>
</tbody>
</table>
<form return onsubmit= "jump (this); return false" >
<div align= "Right" >
Show per page
<input name=pagesize datasrc= #ShopList datafld= page size size=2> strip,
<input type=submit value= "" style= "width:0" >
Total <span id= "PageCount" datasrc= #ShopList datafld= page Quantity ></span> page
<span id= "RecordCount" datasrc= #ShopList datafld= Quantity ></span> section
<input name=firstpage type=submit value= home onclick= "pagenum.value=1" >
<input name=previouspage type=submit value= prev onclick= "pagenum.value=pagenum.value-1" >
<input name=pagenum datasrc= #ShopList datafld= page number size=2> page
<input name=nextpage type=submit value= next page onclick= "pagenum.value= (pagenum.value-0) +1" >
<input name=lastpage type=submit value= last onclick= "Pagenum.value=pagecount.value" >
<input name=pagecount type=hidden datasrc= #ShopList datafld= page Quantity onpropertychange= "Pagecount_onpropertychange ( form) ">
</div> </form>
</body>
-----------------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 (the list ($key, $val) = each ($get _vars)) {
$Vars [$key] = $val;
}
while (List ($key 2, $val 2) = each ($post _vars)) {
$Vars [$key 2] = $val 2;
}
} elseif ($i > 0) {
while (the list ($key, $val) = each ($get _vars)) {
$Vars [$key] = $val;
}
} elseif ($j > 0) {
while (List ($key 2, $val 2) = each ($post _vars)) {
$Vars [$key 2] = $val 2;
}
} else {
$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->close ();
//}
function OutPut ($vars, $cookie) {
/* $strQuery = "SELECT 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 "?>". ";
$xmlStr. = "< store list >". ";
$xmlStr. = "< page tool pageno=" ". $vars [' PageNo ']." "pagesize=". $vars [' pageSize ']. "" total= ". $RecordCount." " ></Flip Tool > "." ";
$xmlStr. = "< page number >". $vars [' PageNo ']. " </page Number > "." ";
$xmlStr. = "< page size >". $vars [' pageSize ']. " </page Size > "." ";
$xmlStr. = "< Quantity >". $RecordCount. " </quantity > "." ";
$xmlStr. = "< page quantity >". $PageCount. " </number of pages > "." ";
$strQuery = "Select 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. = "". " ";
$xmlStr. = "< shop >". ";
$xmlStr. = "< name ><! [cdata[". $result [' Shopname '].]] ></name > "." ";
$xmlStr. = "< operator ><! [cdata[". $result [' Shopmaster '].]] ></operator > "." ";
$xmlStr. = "< level ><! [cdata[". $result [' Shoptype '].]] ></level > "." ";
$xmlStr. = "< Introduction ><! [cdata[". $result [' Shopintro '].]] ></profile > "." ";
$xmlStr. = "< connection address ><! [cdata[personal_shop.php?id=]. $result [' ID '].] ></Connection Address > "." ";
$xmlStr. = "</shop >". ";
}*/
$SC = $vars [' PageNo ']* $vars [' pageSize '];
if ($sc > $RecordCount) $sc = $RecordCount;
for ($i = ($vars [' PageNo ']-1) * $vars [' pageSize ']; $i < $SC; $i + +) {
$xmlStr. = "". " ";
$xmlStr. = "< shop >". ";
$xmlStr. = "< name ><! [cdata[This is the name: ". $i."]] ></name > "." ";
$xmlStr. = "< operator ><! [cdata[This is the operator: ". $i."]] ></operator > "." ";
$xmlStr. = "< level ><! [cdata[This is the level: ". $i."]] ></level > "." ";
$xmlStr. = "< Introduction ><! [Cdata[This is an introduction: ". $i."]] ></profile > "." ";
$xmlStr. = "< connection address ><! [cdata[personal_shop.php?id= ". $i."]] ></Connection Address > "." ";
$xmlStr. = "</shop >". ";
}
$xmlStr. = "</Shop list >". ";
Header ("Content-type:text/xml");
Echo $xmlStr;
}
}
$shoplist = new Shoplist_res ($vars, $HTTP _cookie_vars);
$shoplist->_shoplist_res ();
Unset ($sthoplist);
?>
Above the PHP, the annotation is that I connect the database to obtain the data, since puts up the test, also does not have the database connection, therefore has changed. I am also a newly-picked XML soon, many places still do not understand. Laughed at ...