Home >Backend Development >PHP Tutorial >Smarty simple paging implementation method, smarty paging implementation_PHP tutorial

Smarty simple paging implementation method, smarty paging implementation_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:15:54815browse

How to implement smarty simple paging, smarty paging implementation

The example in this article describes the implementation method of simple paging in smarty and is shared with everyone for your reference. The specific implementation method is as follows:

The following is the smarty code in the template. Use smarty to simply substitute the relevant variables. It is very simple, but the page parameter must be passed in the php code. I think it's a good idea to divide it this way, it's very simple. I like using smarty more and more.

The Php code is as follows:

Copy code The code is as follows:
{if $pageCount > 1}
{foreach item=i from=$pagerList}
{if $pageNum eq $i}
{$i}
{else}
{$i} 
{/if}
{/foreach}
{if $pageNum eq 1}
Previous page
{else}
Previous page 
{/if}
{if $pageNum eq $pageCount }
Next page
{else}
Next page 
{/if}
{if $pageNum eq 1}
Home Page
{else}
Homepage 
{/if}
                                                                        {if $pageNum eq $pageCount}
Last page
{else}
Last page 
{/if}
{/if}
(Total {$pageCount} pages)
Here is just an idea. In fact, paging is not that complicated.

I hope this article will be helpful to everyone’s PHP programming design.

How to achieve digital paging effect in PHP? How to call it in smarty? How to use php code to cycle through the number of pages?

There is a php system that I think uses smarty. You can refer to the

ecshop
mall program. I also plan to learn it. I will start trying to make a system during the Chinese New Year this year and give it to smarty

smarty paging problem

The first method:
The idea is to extract two parts of data based on the page number, such as extracting the first 90 items, then extracting the first 100 items, and then compare the difference between the two results.

In the case of 300,000 records, if it is divided into only 100 pages (the result is 10,000 records), it will take about 1 and a half minutes. If the index is built well, it will take about 1 minute.

//select * from //This sentence cannot be modified, because it is read from the result, so you must use *
//(select top @h_count (@filedlist) from @tableName .....) as big //Get records that meet the upper limit of conditions
//where
//big.guid //Here is the key, filter out duplicate records from the lower limit results based on the primary key (Only leave different data, that is, find the intersection)
//not in
//(select top @l_count guid from @table .....)//lower limit
//order @ orderby //Original format, only the ones after orderby are retained here. Everything after the condition should be retained, including gruopby and so on. The

function is similar to this:
public string MakeSqlPager(string sourceSql,int pageIndex)
{
//Use default page size
string orderbyStr=sourceSql.Substring(sourceSql.ToLower().IndexOf("order by"));
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 be improved, that is, when filtering for the second time, filter from the first result .

Second method:
Pinch off the beginning and end, the program has not been written yet
SELECT * FROM
(
SELECT TOP 100 * FROM
(
SELECT TOP 100000 * FROM pagetest ORDER BY regt ASC
) as a
ORDER BY regt desc
) as b
ORDER BY regt ASC

I tested it and it took about 29 seconds.

Comparison:
The efficiency of the first method is very low. It is guessed because it requires multiple loop comparisons, and the time complexity is one level higher. For example, the response time of this method has a great relationship with the page number obtained.
The second method is still acceptable,...the rest of the text>>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/901286.htmlTechArticleHow to implement smarty simple paging, smarty paging implementation This article describes the implementation method of smarty simple paging, share it with everyone For your reference. The specific implementation method is as follows: The following is...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn