Php? paging

Source: Internet
Author: User
Read n data from the database and want to page out the N data

1, how do I page out this data so that it shows 10 data per page
2. How to calculate the total number of pages

I hope I can give you an example.


Reply to discussion (solution)

 
  

SELECT * FROM table WHERE xxxxxx LIMIT $start _page,10;
$start _page is the number of start bars per page of your

1. First Use SELECT COUNT (*) from table where xxx gets the total number of records
2. (total-1)/10+1 = total number of pages. If total=0, the total number of pages is 0

SELECT * FROM tablename limit 5,10

Pagination can be written like this

$page = 1; To reality the first few pages of data $pagesize = 10; Show 10 data per page $offset = ($page-1) * $pagesize; Calculates the offset number based on the number of pages and records per page $SQLSTR = "SELECT * FROM Table Limit". $offset. ",". $pagesize;

Pagination can be written like this

$page = 1; To reality the first few pages of data $pagesize = 10; Show 10 data per page $offset = ($page-1) * $pagesize; Calculates the offset number based on the number of pages and records per page $SQLSTR = "SELECT * FROM Table Limit". $offset. ",". $pagesize;


$page, $pagesize, $offset These variables to be stored in the session?

No!
$page is incoming.
$pagesize is specified in the program.
$offset is calculated.

Determine the total number of pages according to the total bar, and then how much to check.

  • 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.