PHP paging details

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.