PHP Automatic Paging class function _php Tutorial

Source: Internet
Author: User
PHP Tutorials Automatic Paging class functions

Do not want to repeat the SQL code, use the following function to automatically process.

$__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 Processing SQL statements
$sql _count = preg_replace ('/select.*?from/is ', ' SELECT count (*) as mcnt from ', $sql);
Step 2 Getting the amount of data
$result = DBC ()->query ($sql _count)->getrow ();
$total = $result [' mcnt '];
Step 3 Determine if paging is required
if ($total < $max)
{
return $sql;
}
Step. 4 Get the current page
$PN = Isset ($_get[$flag])? (int) $_get[$flag]: 1;
if ($pn <= 0) $pn = 1;
Step. 5 Reorganizing SQL statements
$sql = $sql. ' Limit '. ($PN-1) * $max. ', '. $max;
Step. 6 assembling 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 = '/previous page ';
}
$NXT = '/Next page ';
$html = ' Home ' $pre. $nxt. '/Last ';
$__t_page_moyo_html = $html;
return $sql;
}


Use Page_moyo to process SQL statements before making SQL queries
$sql = Page_moyo ($sql);
Then call the Page_moyo output directly where you need to display the paging link
Echo Page_moyo ();

If you are going to make two big data SQL queries in a row, store the paging code after the first query, or the next SQL query will overwrite the


http://www.bkjia.com/PHPjc/444794.html www.bkjia.com true http://www.bkjia.com/PHPjc/444794.html techarticle PHP Tutorial Automatic paging class function do not want to repeat the SQL code, the following function to automatically processing. $__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.