Copy codeThe Code is as follows:
<? Php
$ Perpagenum = 10; // defines the number of entries displayed on each page.
$ Total = mysql_fetch_array (mysql_query ("select count (*) from a"); // query the total number of data records in the database
$ Total = $ total [0]; //
$ Totalpage = ceil ($ Total/$ perpagenum); // go to the house and get the integer
If (! Isset ($ _ GET ['page']) |! Intval ($ _ GET ['page']) | $ _ GET ['page']> $ Totalpage) // four possible page states
{
$ Page = 1;
}
Else
{
$ Page = $ _ GET ['page']; // if the preceding conditions are not met, the page value is $ _ GET ['page']
}
$ Startnum = ($ page-1) * $ perpagenum; // number of start entries
$ SQL = "select * from a order by id limit $ startnum, $ perpagenum"; // query the number of required entries
Echo $ SQL ."
";
$ Rs = mysql_query ($ SQL );
$ Contents = mysql_fetch_array ($ rs );
If ($ total) if $ total is not empty, execute the following statement:
{
Do
{
$ Id = $ contents ['id'];
$ Name = $ contents ['name'];
?>
<Table border = "0" align = "center">
<Tr>
<Td> id:
<? Php echo $ id;?>
</Td>
</Tr>
<Tr>
<Td> name:
<? Php echo $ name;?>
</Td>
</Tr>
</Table>
<? Php
}
While ($ contents = mysql_fetch_array ($ rs); // do... while
$ Per = $ page-1; // Previous page
$ Next = $ page + 1; // next page
Echo "<center> Total". $ Total. "records, per page". $ perpagenum. ", Total". $ Totalpage. "Page ";
If ($ page! = 1)
{
Echo "<a href = '". $ _ SERVER ['php _ SELF']. "'> homepage </a> ";
Echo "<a href = '". $ _ SERVER ['php _ SELF']. '? Page = '. $ per. "'> previous page </a> ";
}
If ($ page! = $ Totalpage)
{
Echo "<a href = '". $ _ SERVER ['php _ SELF']. '? Page = '. $ next. "'> next page </a> ";
Echo "<a href = '". $ _ SERVER ['php _ SELF']. '? Page = '. $ Totalpage. "'> last page </a> </center> ";
}
}
Else outputs No message if $ total is null
{
Echo "<center> No message </center> ";
}
?>