We all know that using Php+mysql in the Web page to implement the database data display is very simple and interesting, very few database data in the case of the page display is still satisfactory, but when the database data is very many cases, the page display will be very bad, Here is how to achieve the current page data display number and how to achieve dynamic rollover function.
Here are two ways to implement the flip-page display:
-----------------------------------------------------------
Let's introduce the database syntax used in paging:
mysql_query ("SELECT * from table ORDER BY id DESC");
This database statement is more familiar, is used to search for records and display in reverse order, but it does not work in the paging function, and the following extended syntax is to achieve the core function of paging:
mysql_query ("SELECT * from table ORDER BY id desc limit $start, $limit");
The $start here is the starting line of the database search, $limit from the start line search to the end of the $limit record, OK, with this core function, we can start paging function;
-----------------------------------------------------------
The first kind of page-flipping function:
The function described here is the simplest one in the page-turning function, which can only be used to turn the page forward and turn the page back, the very news of this station and the page-turning function of the Download Center is this.
First, introduce the way to achieve the function of page:
First determine the number of data records that are fixed on the current page, assuming 20 records, set the $limit value to: $limit = 20;
When you display database records, you must start with the first one, so set the initial value of $start to 0: $start = 0;
And the realization of the paging function depends on the dynamic change of $start, when the page is backward $start the law $limit: $start + $limit, while the forward page $start is regularly subtracted $limit: $start-$limit;
With the above ideas, you can begin to design the program page.php:
?
Sets the number of current page displays (this number can be set arbitrarily)
$limit = 20;
Initializing database search start record
if (!empty ($start)) $start = 0;
mysql_connect ("localhost", "", "");
mysql_select_db (database);
Set Total 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);"