PHP Implementation page-out code

Source: Internet
Author: User
This article mainly introduces the PHP implementation page code, has a certain reference value, now share to everyone, the need for friends can refer to

<?phpheader ("Content-type:text/html;charset=utf8"); include ' conn.php ';//The number of data bars displayed per page $pagesise = 2; $result = $conn- >query ("SELECT * from Message");//Data Total $totalnum = $result->num_rows;//Total number of 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 pages, re-assign the Nowpage if ($nowPage > $totalPageCount | | $nowPage = = 0) {//echo "err Or:can not found the page<br> "; $nowPage = $totalPageCount;} Offset $offset = ($nowPage-1) * $pageSise;//sql statement $sql = "SELECT * from Message limit $offset, $pageSise"; $result 2 = $conn Query ($sql);//Output page content while ($row = $result 2->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" ><?phpecho "<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>

The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!

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.