<Script language = "javascript" src = "ajaxpg. js"> </script> <Div id = "result"> <? Php $ Classid = $ _ REQUEST ['classid']; // Note that the data cannot be displayed if the total number of data entries is smaller than the number of data entries per page. $ Page = isset ($ _ GET ['page'])? Intval ($ _ GET ['page']): 1; // obtain the value of the page in page = 18. If there is no page, the page number is 1. $ Num = 10; // 10 data entries per page Require "conn. php "; Mysql_select_db ($ database_lr, $ lr ); /* First, we need to obtain the actual amount of data in the database to determine the specific number of pages to be divided. The specific formula is Total databases divided by the number of entries displayed on each page, more than one. That is to say, 10/3 = 3.3333 = 4 there is a remainder, and we need to enter. */ $ Result = mysql_query ("select * from blog where classid = '$ classid '"); $ Total = mysql_num_rows ($ result); // query all data $ Url = 'show _ main. php'; // obtain the URL of this page // Page number calculation $ Pagenum = ceil ($ total/$ num); // obtain the total number of pages, which is also the last page. $ Page = min ($ pagenum, $ page); // get the homepage $ Prepg = $ page-1; // Previous page $ Nextpg = ($ page = $ pagenum? 0: $ page + 1); // next page $ Offset = ($ page-1) * $ num; // obtain the value of the first parameter of limit. If the first page is (1-1) * 10 = 0, the second page is (2-1) * 10 = 10. // Start the paging navigation bar code: $ Pagenav = $ page. "/". $ pagenum. "& nbsp; <B> & nbsp;". ($ total? ($ Offset + 1): 0 ). "</B>-<B> ". min ($ offset + 10, $ total ). "</B> & nbsp; Total $ total & nbsp ;"; // Page 1: If ($ page = 1 ){ $ Pagenav. = "First & nbsp ;"; } 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> & nbsp; "; else $ pagenav. =" Prev & nbsp ;"; If ($ nextpg) $ pagenav. = "<a href = javascript: dopage ('result', '$ url? Classid = $ classid & page = $ nextpg ');> Next </a> "; else $ pagenav. =" Next "; If ($ pagenum> $ page ){ $ Pagenav. = "& nbsp; <a href = javascript: dopage ('result', '$ url? Classid = $ classid & page = $ pagenum ');> Last </a> "; } Else { $ Pagenav. = "& nbsp; Last "; } $ Pagenav. = "& nbsp; Total page $ pagenum "; // If the input page number parameter is greater than the total page number, the 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"); // obtain the data to be displayed on the corresponding page If ($ total> 0) { While ($ it = mysql_fetch_array ($ info )){ Echo $ it ['title']. "& nbsp; (". $ it ['updatetime']. ")"; Echo "<br> "; Echo $ it ['content']; Echo "<br> "; } // Display data Echo "<br> "; Echo $ pagenav; // output paging navigation } Else { Echo "No comment ."; } ?> </Div> |