Code
1 $ perpagenum = 3; // defines the number of entries displayed on each page
2 $ page = $ _ GET ['page'];
3 $ nextp = $ page + 1;
4 $ backp = $ page-1;
5 $ total = mysql_fetch_array (mysql_query ("select count (*) from text"); // query the total number of data records in the database
6 $ Total = $ total [0]; //
7 $ Totalpage = ceil ($ Total/$ perpagenum); // go to the house and get the integer
8
9
10if (! Isset ($ _ GET ['page']) |! Intval ($ _ GET ['page']) | $ _ GET ['page']> $ Totalpage | $ _ GET ['page'] <1) // four possible page states
11 {
12 $ page = 1;
13}
14 else
15 {
16 $ page = $ _ GET ['page']; // if the preceding four conditions are not met, the page value is $ _ GET ['page']
17}
18
19 $ startnum = ($ page-1) * $ perpagenum; // number of start entries
20
21 $ SQL = "SELECT *
22 FROM 'text'
23 order by 'text'. 'id' DESC limit $ startnum, $ perpagenum "; // SQL query
24 $ result = mysql_query ($ SQL, $ conn );
25 $ row = mysql_fetch_array ($ result );
26
27
28
29 <BODY>
30
31 <div id = "d"> total
32 <? Php echo "$ Total";?>
33, total
34 <? Php echo "$ Totalpage";?>
Page 35
36 <a href = "main. php? Page = <? Php echo $ backp?>" > Previous page </a>
37
38 <a href = "main. php? Page = <? Php echo $ nextp?>" > Next page </a>
39 </div>
40
41 </BODY>
42
43