Simplifying the parsing of pagination code in PHP template pages _php tutorial

Source: Internet
Author: User
Tags php template
When you use a template, you encounter a problem: it is cumbersome to display paging information, and n multiple templates have paging blocks.
For example:
---Total 20 records, current 3/5 page first prev Next last GO-----
The first to encounter this problem of friends, in the consideration of solving this problem seems to be in the idea of PHP, consider how to use PHP to achieve, but no matter how you design after the design of two scenarios
1, using nested loops to achieve
2, with more than n judgment to engage in
But in the end it is more troublesome, and parsing is the use of server-side resources.
You might want to use JavaScript instead of your php!!!! in a different way. , so you can reduce the amount of PHP script code, but also to resolve the paging work to the client itself. But JavaScript can be tricky to debug.
The most important thing is to simplify the page display when the parsing template encounters pain.
The following template is parsed with a ITX template tool that supports pear.
which And Represents a block, {RecordCount} This similar string is a variable.
----------------List.tpl---------------------
Copy CodeThe code is as follows:
Other HTML code








Other HTML code
--------------------Page.js------------
---------------Total 20 records, current 3/5 page first prev 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 = ' ";
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 a template, can also 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.

http://www.bkjia.com/PHPjc/319798.html www.bkjia.com true http://www.bkjia.com/PHPjc/319798.html techarticle when you use a template, you encounter a problem: it is cumbersome to display paging information, and n multiple templates have paging blocks. For example:---A total of 20 records, the current 3/5 page first prev ...

  • Related Article

    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.