PHP Paging A typical PHP page instance code sharing

Source: Internet
Author: User
Copy CodeThe code is as follows:






PHP make page List











































$page/$pages

























'. $i. '
















/** Created on 2010-4-17** Order by Kove Wong*/$link =mysql_connect (' localhost ', ' root ', ' haoxiazai1987 ');mysql_select_db (' pagelist ');mysql_query (' Set names GBK ');$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 numberif (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)) {?> }$page _len = ($page _len%2)? $page _len: $pagelen +1;//page number$pageoffset = ($page _len-1)/2;//page number offset$key = ";$key. = ""; Page, total pagesif ($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 offsetif ($page <= $pageoffset) {$init = 1;$max _p = $page _len;}else{//If the current page is greater than the left offsetIf the right offset of the current page number exceeds the Max page countif ($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. = '';} 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. = ';?>
ID article title







The above introduces PHP paging a typical PHP page instance code sharing, including the content of PHP paging, I hope to be interested in PHP tutorial friends helpful.

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