Home > Article > Backend Development > Smarty simple paging implementation method, smarty paging implementation_PHP tutorial
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:
I hope this article will be helpful to everyone’s PHP programming design.
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
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>>