pagination | templates | page
------------------------
------------------------
This article is written mainly on the "use of templates",
But this method is suitable for any occasion, in any case is a better solution
------------------------
------------------------
In the use of templates, you will encounter a problem: Display paging information when the operation is troublesome, n multiple templates have paging block.
For example:
---Total 20 records, current 3/5 page home previous next last go-----
First encountered this problem, the friend, in the consideration of the problem when it seems to be playing PHP idea, consider how to use PHP to achieve, but no matter how you design are designed in two scenarios
1, with nested loops to achieve
2, with more than n judgment to engage in
But in the end it is troublesome, and the resolution is the use of server-side resources.
You might want to replace your php!!!! with JavaScript in a different way. , so you can reduce the code of PHP script, but also the resolution of paging work to the client itself. But JavaScript debugging can be tricky.
The most important thing is to simplify the paging display, parsing the template encountered pain.
The following template is parsed with a ITX template tool that supports pear.
where <!--BEGIN page--> and <!--end Page--> represent a block, {RecordCount} This similar string is a variable.
----------------List.tpl---------------------
Other HTML code
<table border= "0" cellpadding= "0" cellspacing= "0" width= "100%" >
<TR>
<TD align= "right" nowrap>
<script src= "Images/page.js" language= "JavaScript" ></script>
<script language= "JavaScript" >
<!--BEGIN page-->
RecordCount = {RecordCount};
Show = {Showinonepage}
PageCount = {PageCount};
Pagenow = {page};
Pagestr = "Page=_page_";
document.write (ShowListPage0 (RecordCount, Show, PageCount, Pagenow, pagestr));
<!--end Page-->
</script>
</TD>
</TR>
</TABLE>
Other HTML code
--------------------Page.js------------
---------------Total 20 records, current 3/5 page home previous next last Go-------------------
RecordCount = 20;
Show = 20
PageCount = 5;
Pagenow = 3;
Pagestr = "Page=_page_";
document.write (Showlistpage (RecordCount, Show, PageCount, Pagenow, pagestr));
function ShowListPage0 (RecordCount, Show, PageCount, Pagenow, pagestr) {
if (pagecount<1) PageCount = 0;
if (pagenow<1) Pagenow = 0;
str = ' <form name= ' frmpage ' > Total <B> ' +recordcount+ ' </B> records, current <B> ' +pagenow+ '/' +pagecount+ ' < /b> page ';
if (pagenow<=1)
STR + + "Home";
Else
STR + + "<a href= '" +pagestr.replace ("_page_", 1) + "' > Home </A>";
if (pagenow<=1)
STR + + "prev";
Else
STR + + "<a href= '" +pagestr.replace ("_page_", (pageNow-1)) + "' > Prev </A>";
if (Pagenow>=pagecount)
str = "Next page";
Else
STR + + "<a href= '" +pagestr.replace ("_page_", (pagenow+1)) + "' > Next </A>";
if (Pagenow>=pagecount)
str = "Last";
Else
STR + + "<a href= '" +pagestr.replace ("_page_", PageCount) + "' > Last </A>";
str = "Jump to <input type=\" text\ "name=\" txtpage\ "size=\" 3\ "> page";
STR + + "<input type=\" button\ "value=\" go\ "onclick=\" Pagego0 (Document.frmpage.txtpage.value, "+pagenow+", "+ pagecount+ ", '" +pagestr+ "')" ></form> ";
return str;
}
function Pagego0 (PAGEGO,PAGENOW,PAGECOUNT,PAGESTR) {
if (pagego>=1 && pagego<=pagecount && pagenow!=pagego)
window.location = Pagestr.replace ("_page_", Pagego);
}
----------------------------
In addition, this method, even without templates, can be used, as well as a good paging solution, as long as the {RecordCount} this similar string with the value of the variable to replace it.
----------------------------