PHP pagination Instance Code _php tutorial

Source: Internet
Author: User
PHP Pagination Instance Code





PHP Tutorial make page List















$Page _size=10;

$result =mysql_query (' select * from V_char ');
$count = mysql_num_rows ($result);
$page _count = ceil ($count/$Page _size);

$init = 1;
$page _len=7;
$max _p= $page _count;
$pages = $page _count;

Judging the current page number
if (Empty ($_get[' page ') | | $_get[' page ']<0) {
$page = 1;
}else {
$page =$_get[' page ';
}

$offset = $Page _size* ($page-1);
$sql = "SELECT * from V_char limit $offset, $Page _size";
$result =mysql_query ($sql, $link);
while ($row =mysql_fetch_array ($result)) {
?>







$key = ";
$key. = "$page/$pages "; Page, total pages
if ($page!=1) {
$key. = "First page"; First page
$key. = "Previous page"; Previous page
}else {
$key. = "First page";//First page
$key. = "Previous page"; Previous page
}
if ($pages > $page _len) {
If the current page is less than or equal to the left offset
if ($page <= $pageoffset) {
$init = 1;
$max _p = $page _len;
}else{//If the current page is greater than the left offset
If the right offset of the current page number exceeds the Max page count
if ($page + $pageoffset >= $pages + 1) {
$init = $pages-$page _len+1;
}else{
Calculations when left and right offsets are present
$init = $page-$pageoffset;
$max _p = $page + $pageoffset;
}
}
}
for ($i = $init; $i <= $max _p; $i + +) {
if ($i = = $page) {
$key. = ' . $i. ';
} else {
$key. = "". $i. "";
}
}
if ($page! = $pages) {
$key. = "Next page";//Next page
$key. = "Last page"; Last page
}else {
$key. = "Next page";//Next page
$key. = "Last page"; Last page
}
$key. = ';
?>




/* * Created on 2010-4-17 * * Order by Kove Wong */$link =mysql_connect (' localhost ', ' root ', ' haoxiazai1987 '); MySQL tutorial _select_db (' pagelist '); mysql_query (' Set names GBK '); } $page _len = ($page _len%2)? $page _len: $pagelen +1;//page Number $pageoffset = ($page _len-1)/2;//page number offset
ID article title







http://www.bkjia.com/PHPjc/444757.html www.bkjia.com true http://www.bkjia.com/PHPjc/444757.html techarticle PHP pagination Instance code! DOCTYPE HTML Public-//w3c//dtd XHTML 1.0 transitional//en HTTP://WWW.W3.ORG/TR/XHTML1/DTD/XHTML1-TRANSITIONAL.DTD HTML xmlns=http://www.w3.org/1999/xhtml He ...

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