The principle and realization of the data paging display of PHP from zero single row (14)

Source: Internet
Author: User
Tags sql variable

Paging display is one of the most frequently processed links in web programming. A paging display is a section of the result set that is displayed by a program. To implement a paging display, you need two initial parameters: How many records are displayed per page and the current page number. With the complete result set, the paging display of the data can be realized. As for other functions, such as the previous page, the next page can be processed according to the above information.

To get the first 10 records in a table, you can use the following SQL statement:

SELECT * from A_table LIMIT 0,10

To find records 11th through 20th, the SQL statement used is as follows:

SELECT * from A_table LIMIT 10,10

To find records 21st through 30th, the SQL statement used is as follows:

SELECT * from A_table LIMIT 20,10

The above SQL statement can be seen, each fetch 10 records, the equivalent of 10 data per page display, and each time to obtain a record of the starting position and the number of times between the pages of the relationship between the starting position = (Current page-1) * per page to display the numbers of records. If the number of records displayed per page is represented as a variable $page_size, and the current page is represented as a variable $cur_page, the above can be summed up with the SQL statement template shown below:

SELECT * FROM table limit ($cur _page-1) * $page _size, $page _size;

In this way, you get the SQL statement that gets the data in the paging case. $page_size can be established according to the actual situation as a fixed value, the actual development, the current page $cur_page can be passed through the parameters. In addition, the total number of pages to display for the data can be computed between the total records and the number of records displayed per page. For example, if there is no remainder after the total number of records is divided by the number of records displayed on each page, then the total page count is the quotient of both.

 -->ERROR:". Mysql_error ()."
SQL: ". $sql);?> <title>13-8.php</title>

Post get, is the two ways to submit a form, gets pass value is obtained with $_get, the post submits the form to use $_post
The difference between a post and get is that one displays the argument in the address bar and the other does not display

For example, if you use get when you log in, your values are displayed on the address bar, so there is no security.
And when you search or have page numbers, use post to hide the parameters in the Address bar, which makes no sense.

With $_get, you can get the value of the parameter on the browser's address bar (a string of characters following the question mark), such as www.baidu.com/s?wd=123, then you can get the arguments using $_get (you can understand the event, action, or argument, This value is consistent with the name of input when the form is passed. The value of WD is 123, multiple parameters are connected by &, for example? An=0&si=5 the value of an parameter is 0 and the value of SI parameter is 5.

**********************

For example, you enter an address called www.iron-feet.cn/?page=2
$_get["Page" is to get the value of this page on the address, which is 2



!--? php if ($num =mysql_num_rows ($result)) {while $row =mysql_fetch_array ($result, M YSQL_ASSOC)) {?-- [!--? php}}} echo $t Urn_page; Mysql_close ($conn);?--> **********************
ID Name Sex Age
!--? php echo $row [' id '];?--> !--? php echo $row [' name '];?--> !--? php echo $row [' sex '];?--

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.