Php paging function module sharing _ PHP Tutorial

Source: Internet
Author: User
Php paging function modules. The php paging function module is a list paging function module (the php paging function module) that is very simple and practical, recommended to functional modules with php paging

Here, I will share with you some time ago I made a list page function module (php page function module), which is very simple and practical. I recommend it to anyone who needs it for reference.

First paste a picture to see the effect

Paste the code.

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

$ Localhost = "localhost ";

$ Username = "root ";

$ Password = "root ";

$ Db = "test"; // information

$ Pagesize = 5;

$ Conn = mysql_connect ($ localhost, $ username, $ password); // link to the database

If (! $ Conn ){

Echo "database connection failed". mysql_error ();

}

Mysql_query ("set names 'utf8'"); // Encode and convert

$ Db_select = mysql_select_db ($ db); // select a table

// Query the total number of records

$ Total_ SQL = "select COUNT (*) from page ";

$ Total_result = mysql_query ($ total_ SQL );

$ Total_row_arr = mysql_fetch_row ($ total_result );

$ Total_row = $ total_row_arr [0]; // The total number of items.

// Total number of pages

$ Total = ceil ($ total_row/$ pagesize );

// Current page number

$ Page = @ $ _ GET ['P']? $ _ GET ['P']: 1;

// Lower limit of limit

$ Offset = ($ page-1) * $ pagesize;

$ SQL = "select * from page order by id limit {$ offset}, {$ pagesize }";

$ Result = mysql_query ($ SQL );

Echo"

Small module of PHP paging code

";

Echo"

Echo"

While ($ row = mysql_fetch_assoc ($ result )){

$ Id = $ row ['id'];

$ Name = $ row ['name'];

Echo"

}

Echo"

"; "; ";
ID NAME
". $ Id ." ". $ Name ."
";

// Previous and next pages

$ Pageprev = $ page-1;

If ($ page> $ total ){

$ Pagenext = $ total;

} Else {

$ Pagenext = $ page + 1;

}

// Perform Link jump;

Echo "previous Page Previous Page ";

Mysql_free_result ($ result );

Mysql_close ($ conn );

?>

Key points:

1,

?

1

$ SQL = "select * from page order by id limit {$ offset}, {$ pagesize }";

2,

The code is as follows:

Echo "previous Page Previous Page ";

These two points are the key points that reflect the paging technology and php Code art ~

The above is all the content shared in this article. I hope you will like it.

Tips: I have made a list page function module (php paging function module) some time ago. it is very simple and practical. I recommend it to you...

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.