<script language= "javascript" src= "Ajaxpg.js" ></script> <div id= "Result" > <?php $classid =$_request[' ClassID ']; Note that there is a problem with the data if the total is less than the data per page can not be displayed $page =isset ($_get[' page ')? Intval ($_get[' page '): 1; This is to get the value of page in Page=18, if there is no page, then the page number is 1. $num = 10; Display 10 data per page Require "conn.php"; mysql_select_db ($database _lr, $LR); /* First we have to get the database in the end how much data to determine the specific number of pages, the specific formula is The total database is divided by the number of bars displayed per page. That is to say, 10/3=3.3333=4 will enter one. */ $result =mysql_query ("SELECT * from blog where classid= ' $classid '"); $total =mysql_num_rows ($result); Query all the data $url = ' show_main.php ';//Get the URL of this page Page number calculation $pagenum =ceil ($total/$num); Get the total number of pages, also the last page $page =min ($pagenum, $page);//Get home $PREPG = $page -1;//Previous page $NEXTPG = ($page = = $pagenum 0: $page + 1);//Next page $offset = ($page-1) * $NUM; Gets the value of the first parameter of the limit, if the first page is (1-1) *10=0, and the second page is (2-1) *10=10. To start the pager bar code: $pagenav = $page. " /". $pagenum." <B> ". ($total? ($offset + 1): 0). " </B>-<B> "min ($offset +10, $total)." </B> Total $total "; First page: if ($page ==1) { $pagenav. = "first "; } Else {$pagenav. = "<a href=javascript:dopage (' result ', ' $url? classid= $classid &page=1 ');>first</a>& nbsp; ";} if ($PREPG) $pagenav. = "<a href=javascript:dopage (' result ', ' $url? classid= $classid &page= $prepg '); >prev </a> "; else $pagenav. = "prev "; if ($NEXTPG) $pagenav. = "<a href=javascript:dopage (' result ', ' $url? classid= $classid &page= $nextpg '); >next </a> "; else $pagenav. = "Next"; if ($pagenum > $page) { $pagenav. = " <a href=javascript:dopage (' result ', ' $url? classid= $classid &page= $pagenum '); >last </a> "; } else{ $pagenav. = " Last "; } $pagenav. = " Total Page $pagenum "; If the number of pages passed in is greater than the total number of pages, an error message is displayed if ($page > $pagenum) { echo "Error:can not Found the page". $page; Exit } $info =mysql_query ("SELECT * from blog where classid= ' $classid ' ORDER by id desc limit $offset, $num"); Get the data that the page needs to display if ($total >0) { while ($it =mysql_fetch_array ($info)) { echo $it [' title ']. (". $it [' UpdateTime ']."); echo "<br>"; echo $it [' content ']; echo "<br>"; }//Display data echo "<br>"; echo $pagenav//Output paging navigation } Else { echo "No comment." } ?> </div> |