PHP paging function sample code, PHP page code implementation method, pagination sample Code _php tutorial

Source: Internet
Author: User

PHP paging function sample code, PHP page code implementation method, pagination sample code


PHP Paging function Sample code

Sharing a PHP Paging function code, using this function to implement the paging code is very good.

Code, PHP paging functions.

 $total"If ($lastpg <=1) return false; If only one page jumps out of the IF ($page!=1) $pagecon. = "Home"; else $pagecon. = "Home"; if ($PREPG) $pagecon. = "front page"; else $pagecon. = "front page", if ($NEXTPG) $pagecon. = "Back Page"; else $pagecon. = "Back Page"; if ($page! = $LASTPG) $pagecon. = "Last"; else $pagecon. = "Last"; #下拉跳转列表, cycle through all page numbers $pagecon. = "To\ n ", for ($i =1; $i <= $lastpg; $i + +) {if ($i = = $page) $pagecon. ="$i \ n "; else $pagecon. ="$i \ n ";} $pagecon. = "Page, total $lastpg page ";}} Else Die (' pagedivide () the same name function already exists! ');? >

Articles you may be interested in:
Entry-level PHP simple page pagination code
PHP pagination Code details (with example)
A simple example of PHP page pagination code
PHP Paging class with a variety of paging methods
A handy PHP paging class
Example of a simple PHP page-out code
A useful PHP page-out class
A fast and easy-to-use PHP paging class


PHP Paging Code

I'll give you a class, it's simple,
Paging functions
Class pg{
Function Genpage (& $sql, $page _size=2)
{
Global $prepage, $nextpage, $pages, $sums; Out param
$page = $_get["page"];
$eachpage = $page _size;
$pagesql = Strstr ($sql, "from");
$pagesql = "SELECT count (*) as IDs". $pagesql;
$result = mysql_query ($pagesql) or Die (Mysql_error ());
if ($rs = mysql_fetch_array ($result)) $sums = $rs [0];
$pages = Ceil (($sums -0.5)/$eachpage)-1;
$pages = $pages >=0? $pages: 0;
$prepage = ($page >0)? $page -1:0;
$nextpage = ($page < $pages)? $page + 1: $pages;
$startpos = $page * $eachpage;
$sql. = "Limit $startpos, $eachpage";
}
function ShowPage ()
{
Global $page, $pages, $prepage, $nextpage, $queryString;
$queryString =$_server[' query_string '];
if (Preg_match ("/page/", $queryString)) {
$queryString =strstr ($queryString, "&");
}else {
$queryString = "&". $queryString;
}

$shownum =10/2;
$startpage = ($page >= $shownum)? $page-$shownum: 0;
$endpage = ($page + $shownum <= $pages)? $page + $shownum: $pages;
$xs = "";
$xs. = "Total". ($pages + 1). " Page: ";
if ($page >0) $xs. = "Home </a>";
if ($startpage >0)
$xs. = "...? </a> Remaining full text >>

PHP Paging Code

Include ("connection.php");
$perNumber = 10; The number of records displayed per page
$page =$_get[' page '; Get the current page value
$count =mysql_query ("SELECT count (*) from user"); Total Records obtained
$rs =mysql_fetch_array ($count);
$totalNumber = $rs [0];
$totalPage =ceil ($totalNumber/$perNumber); Calculate the total number of pages
if (!isset ($page)) {
$page = 1;
}//If there is no value, assign a value of 1
$startCount = ($page-1) * $PERNUMBER; Start with pagination and calculate the starting record based on this method
$result =mysql_query ("SELECT * from User limit $startCount, $perNumber"); Based on the previous calculation, the number of records and records started
while ($row =mysql_fetch_array ($result)) {
echo "user_id:". $row [0]. "
";
echo "Username:". $row [1]. "
"; Displaying the contents of a database
}
if ($page! = 1) {//pages not equal to 1
?>
"> Prev </a>
}
for ($i =1; $i <= $totalPage; $i + +) {//Cycle Show page
?>
"> </a>
}
if ($page < $totalPage) {//If page is less than total pages, show next link
?>
"> Next </a>
}
?>
================================

This is very simple. And also wrote a note. I don't know if it's your idea.

http://www.bkjia.com/PHPjc/881270.html www.bkjia.com true http://www.bkjia.com/PHPjc/881270.html techarticle PHP Paging function sample code, PHP page code implementation method, pagination sample Code PHP page function sample code share a PHP paging function code, using this function to implement pagination code is very good. ...

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