Php automatic paging functions. In the php Tutorial, if the automatic paging function does not want to repeatedly write SQL code, the following function is used for automatic processing. $ __T_page_moyo_html; *** temporary code: Paging processing function * @ para php Tutorial automatic paging class function
If you do not want to repeatedly write SQL code, use the following function to automatically process it.
$ __T_page_moyo_html = '';
/**
*
* Temporary code: Paging processing function
* @ Param string $ SQL
*/
Function page_moyo ($ SQL = '')
{
Global $ __t_page_moyo_html;
If ($ SQL = '')
{
Return $ __t_page_moyo_html;
}
// Config
$ Max = 12;
$ Flag = 'page ';
// Step. 1 process SQL statements
$ SQL _count = preg_replace ('/select .*? From/is ', 'SELECT count (*) as mcnt from', $ SQL );
// Step. 2 get the data volume
$ Result = dbc ()-> query ($ SQL _count)-> getrow ();
$ Total = $ result ['mcnt '];
// Step. 3 determine whether paging is required
If ($ total <$ max)
{
Return $ SQL;
}
// Step. 4 get the current page number
$ Pn = isset ($ _ get [$ flag])? (Int) $ _ get [$ flag]: 1;
If ($ pn <= 0) $ pn = 1;
// Step. 5 reorganize the SQL statement
$ SQL = $ SQL. 'limit '. ($ pn-1) * $ max.', '. $ max;
// Step. 6 assemble the paging html code
$ Url = $ _ server ['request _ uri '];
If (preg_match ('/'. $ flag. '= d +/I', $ url ))
{
$ Url = preg_replace ('/[&]? '. $ Flag.' = d +/', '', $ url );
}
$ Pageall = ceil ($ total/$ max );
$ Pre = '';
If ($ pn> 1)
{
$ Pre = '/ ';
}
$ Nxt = '/ ';
$ Html = 'homepage '. $ pre. $ nxt.'/end page ';
$ __T_page_moyo_html = $ html;
Return $ SQL;
}
Use page_moyo to process SQL statements before performing SQL queries.
$ SQL = page_moyo ($ SQL );
Then, call page_moyo to display the paging link.
Echo page_moyo ();
If you want to perform two consecutive SQL queries with large data volumes, you need to store the paging code after the first query. Otherwise, the next SQL query will overwrite it.
Automatic paging functions do not want to repeatedly write SQL code, so they can be automatically processed using the following functions. $ __T_page_moyo_html = '';/***** temporary code: Paging processing function * @ para...