Copy codeThe Code is as follows:
<? Php
// Connect to the database
$ Db = mysql_connect ("localhost", "root ","");
Mysql_select_db ("hy", $ db );
// Set the number of records displayed on each page
$ Pagesize = 25;
// Obtain the total number of records and calculate the total number of pages
$ Res = mysql_query ("select count (*) from main", $ db );
$ Myrow = mysql_fetch_array ($ res );
$ Numrows = $ myrow [0];
// Calculate the total number of pages
$ Pages = intval ($ numrows/$ pagesize );
If ($ numrows % $ pagesize)
$ Pages ++;
// Determine whether the page number is set or not. If not, the page number is defined as the homepage.
If (! Isset ($ page ))
$ Page = 1;
// Determine the number of pages to be transferred
If (isset ($ ys ))
If ($ ys> $ pages)
$ Page = $ pages;
Else
$ Page = $ ys;
// Calculate the record offset
$ Offset = $ pagesize * ($ page-1 );
// Retrieve records
$ Res = mysql_query ("select id, title from main order by id desc limit $ offset, $ pagesize", $ db );
// Display records cyclically
If ($ myrow = mysql_fetch_array ($ res ))
{
$ I = 0;
?>
<Table width = "101%" border = "0" cellspacing = "0" cellpadding = "0">
<Tr>
<Td width = "5%" bgcolor = "# E1E9FB"> </td>
<Td width = "95%" bgcolor = "# E1E9FB"> <font color = "# FF6666" size = "2"> content </font> </td>
</Tr>
<? Php
Do {
$ I ++;
?>
<Tr>
<Td width = "5%" bgcolor = "# E6F2FF"> <? Php echo $ I;?> </Td>
<Td width = "95%" bgcolor = "# E6F2FF"> <font size = "2">
<A href = "javascript: popwin ('view. php? Id = <? Php echo $ myrow [0];?> ') "> <? Php echo $ myrow [1];?> </A> </font> </td>
</Tr>
<? Php
}
While ($ myrow = mysql_fetch_array ($ res ));
Echo "</table> ";
}
// Display the total number of pages
Echo "<div align = 'center'> total". $ pages. "page (". $ page. "/". $ pages. ") <br> ";
// Display the number of pages
For ($ I = 1; $ I <$ page; $ I ++)
Echo "<a href = 'fenye. php? Page = ". $ I." '> page ". $ I." </a> ";
Echo "page". $ page ";
For ($ I = $ page + 1; $ I <= $ pages; $ I ++)
Echo "<a href = 'fenye. php? Page = ". $ I." '> page ". $ I." </a> ";
Echo "<br> ";
// Display to page number
Echo "<form action = 'fenye. php' method = 'post'> ";
// Calculate the number of pages on the home page, Previous Page, next page, and last page
$ First = 1;
$ Prev = $ page-1;
$ Next = $ page + 1;
$ Last = $ pages;
If ($ page> 1)
{
Echo "<a href = 'fenye. php? Page = ". $ first." '> homepage </a> ";
Echo "<a href = 'fenye. php? Page = ". $ prev." '> previous page </a> ";
}
If ($ page <$ pages)
{
Echo "<a href = 'fenye. php? Page = ". $ next." '> next page </a> ";
Echo "<a href = 'fenye. php? Page = ". $ last." '> last page </a> ";
}
Echo "go to <input type = text name = 'ys 'size = '2' value =". $ page. "> page ";
Echo "<input type = submit name = 'submit 'value = 'Go'> ";
Echo "</form> ";
Echo "</div> ";
?>