Php+mysql Paging principle

Source: Internet
Author: User

1. Limit usage in SQL statements

SELECT * FROM table ... limit start position, number of operation bars (start position starting from 0)

SELECT * FROM Table ... limit 0, 20 (take front 20)

SELECT * FROM Table ... limit 10, 20 (starting from 11 fetch 20)


2. A formula for learning pagination

(1) Paging principle

The so-called paging display, that is, the result set in the database, a section of the display

(2) Required conditions

How to segment, current in the first paragraph (there are several pages per page, the current second page)

Top 10 Records: SELECT * FROM table limit 0,10

11th to 20th record: SELECT * FROM table limit 10,10

21st to 30th Record: SELECT * FROM table limit 20,10

(3) Get the formula

(Current page-1) x number of pages per page, number of articles per page

Select * FROM table limit ($Page-1) * $PageSize, $PageSize



3. Parse_url () Parse URL function

Parse_url () is a function that parses a URL into an array with fixed key values.

$ua =parse_url ("Http://username:[email protected]/path?arg=value#anchor");p Rint_r ($ua); Result: Array ([scheme] = HTTP [Host] = hostname [user] = username [pass] = password [path] +/path [query] = arg =value [Fragment] = anchor)



4.$_server["Request_url"] function

One of the predefined server variables, all at the beginning of the $_server, called Predefined server variables

Request_url is the function to get the current URL, but also the full address path in addition to the domain name


The current page is: http://www.php.com/home.php?id=23&cid=22

echo $_server["Request_url"]

Results:/home.php?id=23&cid=22








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.