Smarty simple paging implementation, smarty paging implementation

Source: Internet
Author: User

Smarty simple paging implementation, smarty paging implementation

The example in this article describes how to implement smarty simple paging and shares it with you for your reference. The specific implementation method is as follows:

The following is the smarty code in the template. You can simply use smarty to replace the relevant variables. It is very simple, but you need to input the page parameter in the php code. I think this is quite simple. I like smarty more and more.
 
The Php code is as follows:
Copy codeCode: {if $ pageCount> 1}
{Foreach item = I from = $ pagerList}
{If $ pageNum eq $ I}
{$ I}
{Else}
<A href = "/space/index. php? Uid = {$ userId} & page = {$ I} ">{$ I} </a>
{/If}
{/Foreach}
{If $ pageNum eq 1}
Previous Page
{Else}
<A href = "/space/friendlist. php? Uid = {$ userId} & page = {$ pagePre} "> previous page </a>
{/If}
{If $ pageNum eq $ pageCount}
Next Page
{Else}
<A href = "/space/friendlist. php? Uid = {$ userId} & page = {$ pageNext} "> next page </a>
{/If}
{If $ pageNum eq 1}
Homepage
{Else}
<A href = "/space/friendlist. php? Uid = {$ userId} & page = 1 "> homepage </a>
{/If}

{If $ pageNum eq $ pageCount}
Last page
{Else}
<A href = "/space/friendlist. php? Uid = {$ userId} & page = {$ pageCount} "> last page </a>
{/If}
{/If}
({$ PageCount} pages in total)

Here is just an idea. In fact, paging is not that complicated.

I hope this article will help you with PHP programming.


How does PHP achieve digital paging? How is it called in smarty? How to Use php code to loop the number of pages?

There is a php system. I think it uses smarty. You can refer to it.
Ecshop
I plan to learn the mall program. This year, I started to try to build a system to give smarty

Smarty Paging

Method 1:
The idea is to extract two parts of data based on the page number, for example, extract the first 90, then extract the first 100, and then compare the difference set of the two results.

In the case of 0.3 million records, it takes about one minute and a half if only 100 pages are divided (10000 records are returned. If the index is created, it takes about 1 minute.

// Select * from // The statement cannot be modified because it is read from the result and must be used *
// (Select top @ h_count (@ filedlist) from @ tableName...) as big // retrieve records that meet the upper limit
// Where
// Big. guid // This is the key. duplicate records are filtered out from the lower limit results based on the primary key (only different data is left, that is, intersection)
// Not in
// (Select top @ l_count guid from @ table...) // lower limit
// Order @ orderby // The original format. Only the values after orderby are retained here. The values after the conditions should be retained, including gruopby and others.

The function is similar to this:
Public string MakeSqlPager (string sourceSql, int pageIndex)
{
// Use the default page size
String orderbyStr = sourceSql. Substring (sourceSql. ToLower (). IndexOf ("order "));
Int index = sourceSql. ToLower (). IndexOf ("select ");
String bigRes = "(" + sourceSql. insert (index + 6, "top" + (pageIndex + 1) * _ pageSize ). toString () + "") + ") as big ";
String smallRes = "(" + sourceSql. Insert (index + 6, "top" + (pageIndex * _ pageSize). ToString () + "") + ")";
Return "select * from" + bigRes + "where big. guid not in" + smallRes + "" + orderbyStr;
}

This method can also be improved by filtering from the first result when Filtering for the second time.

Method 2:
The program has not been written.
SELECT * FROM
(
Select top 100 * FROM
(
Select top 100000 * FROM pagetest order by regt ASC
) As
Order by regt desc
) As B
Order by regt ASC

Tested. It took about 29 seconds.

Comparison:
The efficiency of the first method is very low, because it requires loop comparison for multiple times, and the time complexity is a level higher. For example, the response time of this method is closely related to the obtained page number.
The second method is acceptable,... the remaining full text>

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.