Today's exercise, paging code

Source: Internet
Author: User

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}‘>&nbsp;[{$i}]</a>"; }

}
Echo $ P;
?>

Today's exercise, paging code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.