The problem has been solved! Thank you for your answers!
The problem persists. It is estimated that database traversal is an error. Two pieces of information are displayed on each page, but no matter what page is, the first page of information is displayed. To be resolved.
<? PHP
Error_reporting (0 );
Require_once ("include. php ");
$ SQL = "select * from user ";
$ Totalrows = getresultnum ($ SQL); // use the preset custom function to get the total number of rows. In fact, it is mysql_fetch_rows.
// Print_r ($ totalrows );
// Two messages are displayed on each page.
$ Pagesize = 2;
$ Totalpage = Ceil ($ totalrows/$ pagesize); // calculate the total page number, and use Ceil to get the integer
$ Page = $Request ['page']? $Request ['page']: 1;
If ($ page <1 | $ page = NULL |! Is_numeric ($ page) {// Add! Is_numberic.
# If the page number is smaller than 1, empty, or non-numeric in the request, the first page is $ page = 1 by default;
} If ($ page >=$ totalpage) {// If the page number is greater than or equal to totalpage, it is the last page by default.
$page = $totalpage;
}
// Offset Formula
$ Offset = ($ page-1) * $ pagesize;
$ SQL = "select * from user limit {$ offset}, {$ pagesize}";
$ Query = mysql_query ($ SQL );
$ Url = $ _ server ['php _ Self '];
While ($ result = mysql_fetch_array ($ query ))
{
Echo "No.:". $ result ['uid']. "<br>"; echo "name:". $ result ['user']. "<HR> ";
}
For ($ I = 1; $ I <= $ totalpage; $ I ++ ){
// The current page number is not connected
if($page==$i){$p.="<a href=‘$url?page={$i}‘>[{$i}]</a>";}else{ $p.="<a href=‘$url?page={$i}‘> [{$i}]</a>"; }
}
Echo $ P;
?>
Today's exercise, paging code