Powerful page flip function

Source: Internet
Author: User
We all know that using php + mysql to display all database information on the web page is very simple and interesting. When there are few database information, the page is still satisfactory, however, when there are a lot of database information, the page display will become very bad, the following describes how to display the data volume on the current page and how to implement the dynamic flip function.
Here we will introduce the implementation of two page flip display functions:
-----------------------------------------------------------
First, we will introduce the database syntax used in Paging:
Mysql_query ("select * from table order by id desc ");
This database statement is no longer familiar. It is used to search records and display them in reverse order, but does not play a role in the paging function, the extended syntax below is the core function of page flip:
Mysql_query ("select * from table order by id desc limit $ start, $ limit ");
Here, $ start is the starting row for database search, and $ limit is the starting row to search for $ limit Records. Well, with this core function, we can start the page flip function;
-----------------------------------------------------------
The first page flip function:
The features described here are the simplest of the page flip function. You can only flip the pages forward and backward. This is the paging function of the news and download center on this site.
The following describes how to implement the paging function:
First, determine the number of data records displayed on the current page. For example, 20 records are displayed. Set the value of $ limit to 20: $ limit = 20;
When displaying database records, it must start from the first entry. Therefore, the initial value of $ start is set to 0: $ start = 0;
The implementation of the page flip function depends on the dynamic changes of $ start. When the page is turned back, $ limit: $ start + $ limit is added to the $ start rule; when you flip the page forward, $ start is regularly subtracted from $ limit: $ start-$ limit;
With the above ideas, you can start designing the page. php program:
<?
// Set the quantity displayed on the current page (this quantity can be set as needed)
$ Limit = 20;
// Initialize the Start Record of the database search
If (! Empty ($ start) $ start = 0;
Mysql_connect ("localhost ","","");
Mysql_select_db (database );
// Set the total number of database records
$ Result = mysql_query ("select * from table ");
$ Num_max = mysql_numrows ($ result );
$ Result = mysql_query ("select * from table order by id desc limit $ start, $ limit );
$ Num = mysql_numrows ($ result );
Echo "<table> <tr> <td> Page Flip function </td> </tr> ";
If (! Empty ($ num )){
For ($ I = 0; $ I <$ num; $ I ++ ){

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.