xml+php dynamic loading and paging _php Foundation

Source: Internet
Author: User
Tags cdata vars

This is seen in the Pacific Network Review, 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>
&LT;TD height= "colspan=" 4 "><span class=" Shop_3d_text "> Store list </span></td>
</tr>
<tr>
&LT;TD width= "30%" > Shop name </td>
&LT;TD width= "20%" > Operator </td>
&LT;TD width= "20%" > Shop level </td>
&LT;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\ "?>". \ n ";
$xmlStr. = "< store list >". \ n ";
$xmlStr. = "\t< paging tool pageno=\". $vars [' PageNo ']. " \ "Pagesize=\" ". $vars [' pageSize ']." \ "Total=\" ". $RecordCount." \ "></page-flipping tool >". \ n ";
$xmlStr. = "\t< page number >". $vars [' PageNo ']. " </page Number > "." \ n ";
$xmlStr. = "\t< page size >". $vars [' pageSize ']. " </page Size > "." \ n ";
$xmlStr. = "\t< quantity >". $RecordCount. " </quantity > "." \ n ";
$xmlStr. = "\t< page quantity >". $PageCount. " </number of pages > "." \ n ";
$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. = "\ T". " \ n ";
$xmlStr. = "\t< shop >". \ n ";
$xmlStr. = "\t\t< name ><! [cdata[". $result [' Shopname '].]] ></name > "." \ n ";
$xmlStr. = "\t\t< operator ><! [cdata[". $result [' Shopmaster '].]] ></operator > "." \ n ";
$xmlStr. = "\t\t< level ><! [cdata[". $result [' Shoptype '].]] ></level > "." \ n ";
$xmlStr. = "\t\t< Introduction ><! [cdata[". $result [' Shopintro '].]] ></profile > "." \ n ";
$xmlStr. = "\t\t< Connection address ><! [cdata[personal_shop.php?id=]. $result [' ID '].] ></Connection Address > "." \ n ";
$xmlStr. = "\t</shop >". \ 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< shop >". \ n ";
$xmlStr. = "\t\t< name ><! [cdata[This is the name: ". $i."]] ></name > "." \ n ";
$xmlStr. = "\t\t< operator ><! [cdata[This is the operator: ". $i."]] ></operator > "." \ n ";
$xmlStr. = "\t\t< level ><! [cdata[This is the level: ". $i."]] ></level > "." \ n ";
$xmlStr. = "\t\t< Introduction ><! [Cdata[This is an introduction: ". $i."]] ></profile > "." \ n ";
$xmlStr. = "\t\t< Connection address ><! [cdata[personal_shop.php?id= ". $i."]] ></Connection Address > "." \ n ";
$xmlStr. = "\t</shop >". \ n ";
}
$xmlStr. = "</Shop list >". \ n ";
Header ("content-type:text/xml\n\n");
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 ...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.