<? Php
// Establish a database connection
$ Link = mysql_connect ("localhost", "root", "wyh7ye ");
; // Obtain the current page number
Mysql_select_db ("test", $ link );
If (isset ($ _ GET ['page'])... {
$ Page = intval ($ _ GET ['page']);
}
Else ...{
$ Page = 1;
}
// Number of pages per page
$ Page_size = 4;
// Obtain the total data volume
$ SQL = "select * from user ";
$ Result = mysql_query ($ SQL, $ link );
While ($ row = mysql_fetch_array ($ result ))...{
$ I = $ I + 1;
}
$ Amount = $ I;
// Count the total number of pages
If ($ amount )...{
If ($ amount <$ page_size)... {$ page_count = 1 ;}// if the total data volume is less than $ PageSize, there is only one page
If ($ amount % $ page_size)... {// retrieve the total data volume divided by the remainder of each page
$ Page_count = (int) ($ amount/$ page_size) + 1; // if there is a remainder, the number of pages equals the total data volume divided by the result of each page number and then adds one
} Else ...{
$ Page_count = $ amount/$ page_size; // if there is no remainder, the number of pages equals the total data volume divided by the result of each page
}
}
Else ...{
$ Page_count = 0;
}
// Obtain data and return results in two-dimensional array format
If ($ amount )...{
$ SQL = "select * from user order by id desc limit". ($ page-1) * $ page_size. ", $ page_size ";
$ Result = mysql_query ($ SQL, $ link );
While ($ row = mysql_fetch_array ($ result ))...{
?>
<Table width = "100%" border = "0" cellspacing = "2" cellpadding = "0">
<Tr>
<Td bgcolor = "# CCCCCC" width = "25%"> <? Php echo $ row [0];?> </Td>
<Td bgcolor = "# FFCCFF" width = "25%"> <? Php echo $ row [1];?> </Td>
<Td bgcolor = "# FFFFCC" width = "25%"> <? Php echo $ row [2];?> </Td>
<Td bgcolor = "# CCCCCC" width = "25%"> <? Php echo $ row [3];?> </Td>
</Tr>
</Table>
<? Php
}
}
// Flip Link
$ Page_string = "";
If ($ page = 1 )...{
$ Page_string. = "first page | Previous Page | ";
}
Else ...{
$ Page_string. = "<a href =? Page = 1> page 1 </a> | <
Href =? Page = ". ($ page-1)."> previous page </a> | ";
}
If ($ page = $ page_count) | ($ page_count = 0 ))...{
$ Page_string. = "next page | last page ";
}
Else ...{
$ Page_string. = "<a href =? Page = ". ($ page + 1)."> next page </a> | <a href =? Page = ". $ page_count."> last page </a> ";
}
Echo $ page_string;
?>
<Br>