PHP instance Tutorial: implements the dynamic flip function. LieHuo. Net PHP Tutorial 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 full.
Tutorial on PHP of Kangli website building Institute (Bkjia. Com)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 display is 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.
This article introduces 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 type of page flip function is described here, which is the simplest of the page flip function. it can only be used to flip pages forward and backward. this is the paging function of the news and download center on this site. First, we will introduce how to implement the paging function. First, we will determine the number of fixed data records displayed on the current page. for example, if there are 20 records, we will 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:
Reference content is as follows: // 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" If (! Empty ($ num )){ For ($ I = 0; $ I <$ num; $ I ++ ){ $ Val = mysql_result ($ result, $ I, "val "); $ Val1 = mysql_result ($ result, $ I, "val1 "); Echo"
Echo"
Page Flip function |
";
$ Val |
$ Val1 |
";}}
"; // Set the jump to the forward page $ Prve = $ start-$ limit; If ($ prve> = 0 ){ Echo "prve "; } // Set the jump to the back page $ Next = $ start + $ limit; If ($ next <$ num_max ){ Echo "next "; } Echo" |
"; ?> |
A front flip and a back flip are completed. however, this function will be cumbersome to process more data display. next we will continue to introduce the more powerful and more complex page turning feature-loop page turning (I have always called this because I cannot find a more appropriate name ). :)
- Three pages in total:
- Previous Page
- 1
- 2
- 3
- Next page
Digest (LieHuo. net) PHP tutorials 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 full...