The implementation result is shown in the figure below:
The code is not described in detail. The comment contains 1 <? PHP
2 // Page Current page, number of pages per page of num
3 $ page = isset ($ _ Get ['page'])? Intval ($ _ Get ['page']): 1;
4 $ num = 5;
5
6 $ conn = mysql_connect ('127. 0.0.1 ', 'root ','');
7 if (! $ Conn ){
8 die ('could not connect: '. mysql_error ());
9}
10 mysql_select_db ('shop ');
11 // obtain the total number of records
12 $ Total = mysql_num_rows (mysql_query ("select * from user "));
13 // calculate the page number
14 $ pagenum = Ceil ($ total/$ num );
15 // the maximum number of pages cannot be exceeded.
16 if ($ page> $ pagenum | $ page = 0 ){
17 echo 'error: Can not found the page .';
18 exit;
19}
20 // the statement "select * from Table limit" extracts ten pieces of information from the table. 0 indicates the start point and 10 indicates the number of extracted items.
21 // $ offset is the start value. For example, if the current page is the first page and there are 5 entries on each page, the start point is 0. Similarly, if the current page is the second page, the start point is 5.
22 $ offset = ($ page-1) * $ num;
23 $ result = mysql_query ("select * from user limit $ offset, $ num ");
24 while ($ it = mysql_fetch_array ($ result )){
25 echo 'id: '. $ it ['id']. 'name:'. $ it ['name']. '<br/> ';
26}
27 // display link page switch link, no link on the current page
28 For ($ I = 1; $ I <= $ pagenum; $ I ++ ){
29 $ show = ($ I! = $ Page )? "<A href = 'index. php? Page = ". $ I." '> $ I </a> ":" <B> $ I </B> ";
30 echo $ show ."";
31}
32 echo $ total. 'records, 5 records per page, total '. $ pagenum.' page ';
33 mysql_free_result ($ result );
34 mysql_close ($ conn );
35?>