Php automatic paging function _ PHP Tutorial

Source: Internet
Author: User
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...

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.