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." >«</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." >»</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!