PHP Paging implementation

Source: Internet
Author: User

<?phpheader ("Content-type:text/html;charset=utf8"); include ' conn.php ';
Number of data bars displayed per page $pagesise = 2;
$result = $conn->query ("SELECT * from Message"),//Data total number $totalnum = $result->num_rows;//Total pages $totalpagecount = Ceil ( $totalNum/$pageSise);
Determine which page is currently $nowpage = isset ($_get[' page ')? Intval ($_get[' page '): 1;//prev $prev = ($nowPage-1 <=0)? 1: $nowPage -1;//Next $next = ($nowPage +1>= $totalPageCount)? $totalPageCount: $nowPage +1;//If the number of pages passed in is greater than the total page count, the Nowpage is assigned again
if ($nowPage > $totalPageCount | | $nowPage = = 0) {//echo "Error:can not found the page<br>"; $nowPage = $totalPageCo UNT;}
Offset amount
$offset = ($nowPage-1) * $pageSise;
SQL statements
$sql = "SELECT * from Message limit $offset, $pageSise"; $result 2 = $conn->query ($sql);//Output page content while ($row = $result 2-&gt ; Fetch_assoc ()) {echo $row [' user ']. ' | '. $row [' title ']. ' <br> ';}? >
<!--page start, first write the pagination HTML and css--> <link href= "//cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css" rel= " Stylesheet "> <script src="//cdn.bootcss.com/jquery/2.1.1/jquery.min.js "></script> <script src="/ /cdn.bootcss.com/bootstrap/3.3.6/js/bootstrap.min.js "></script> <ul class=" pagination "> <?php echo "<li><a href= '". $_server[' Php_self ']. "? Page=1 ' > Home </a></li> '; echo "<li><a href= '". $_server[' Php_self ']. "? Page= ". $prev." >&laquo;</a></li> ";?> <?php $page = 5; for ($a =1; $a <= $page; $a + +) {echo "<li><a href= '". $_server[' Php_self ']. "? Page= ". $a." > $a </a></li> "; }?>
<?php echo "<li><a href= '". $_server[' Php_self ']. "? Page= ". $next." >&raquo;</a></li> "; echo "<li><a href= '". $_server[' Php_self ']. "? Page= ". $totalPageCount." > End </a></li> ";?></ul>







PHP Paging implementation

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.