We all know that it is very simple and interesting to use php+mysql to display all database information on a web page. When the database information is very small, the page display is still satisfactory, but when there is a lot of database information, the page display The situation will become very bad. Let's introduce how to display the number of data 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 introduce the database syntax used in page turning:
mysql_query("select * from table order by id desc");
This database statement couldn't be more familiar. , is used to search for records and display them in reverse order, but it does not work in the page turning function. The following extended syntax is the core function of page turning:
mysql_query("select * from table order by id desc limit $start,$limit");
The $start here is the starting row of database search, and $limit is the search starting from the starting row and ending with $limit records. Okay, with this core After the function, we can start the page turning function;
------------------------------------------------ -----------------------
The first page turning function:
The function introduced here is the simplest one among the page turning functions. , can only realize page turning forward and page turning backward. This is the page turning function of the special news and download center of this site.
First introduce the idea of implementing the page turning function:
First make sure that the current page is fixed The number of data records to be displayed, assuming it is 20 records, set the value of $limit to 20: $limit=20;
When displaying database records, they must be displayed from the first one, so the initial value of $start is set here The value is 0: $start=0;
The implementation of the page turning function relies on the dynamic change of $start. When turning the page backward, $start regularly adds $limit: $start+$limit; while turning the page forward When $start, $limit is subtracted regularly: $start-$limit;
After having the above ideas, you can start designing the program page.php:
//Set the current page The number displayed (this number can be set arbitrarily)
$limit=20;
//Initialize the database search starting record
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>