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 ...