Fully explain the paging display Example Analysis of PHP + MySQL 22

Source: Internet
Author: User

$ QH = mysql_query ("select count (*) as rcnt from table where your_condition_here order by whatever");
$ DATA = mysql_fetch_array ($ QH );
$ Nr = $ data ["rcnt"];
// determine whether the offset parameter is passed to the script, if not, use the default value 0
If (empty ($ offset)
{< br> $ offset = 0;
}< br> // query result (20 entries per page, but you can change it by yourself)
$ result = mysql_query ("select ID, name, phone from table where your_condition_here order by whatever limit $ offset, 20 ");

// display the returned 20 records
while ($ DATA = mysql_fetch_array ($ result ))
{< br> // replace it with the Code
}< br> // next step, link to write to other pages
If (! $ Offset) // If the offset is 0, the link to the previous page is not displayed
{< br> $ preoffset = $ offset-20;
Print " previous page & nbsp ;";
}< br> // calculate the total number of required pages
$ pages = Ceil ($ NR/20 ); // $ pages variable now contains the required page number
for ($ I = 1; $ I <= $ pages; $ I)
{< br> $ newoffset = 20 * $ I;
Print "$ I & nbsp;";
}< br> // check whether it is the last page
if ($ pages! = 0 & ($ newoffset/20 )! = $ Pages)
{< br> Print " next page & nbsp;";
}< BR >?>

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.