PHP Paging function module Sharing _php Tutorial

Source: Internet
Author: User

PHP Paging function module sharing


Here to share is that the individual has made a list of the previous time the function module (PHP paging function module), very simple and practical, recommended for the needs of small partners under the reference.

Put a picture first to see the effect.

Just post the code.

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21st

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 Database

if (! $conn) {

echo "Database link Failed". mysql_error ();

}

mysql_query ("SET NAMES ' UTF8 '"); Code Conversion

$DB _select = mysql_select_db ($db); Select Table

Total Query 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]; Total number of bars

Total pages

$total = ceil ($total _row/$pagesize);

Current page

$page = @$_get[' P ']? $_get[' P ']: 1;

Limit limit

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

$sql = "SELECT * from page order by ID limit {$offset},{$pagesize}";

$result = mysql_query ($sql);

echo "

PHP pagination code for small modules

";

echo "

echo "

while ($row = Mysql_fetch_assoc ($result)) {

$id = $row [' id '];

$name = $row [' name '];

echo "

}

echo "

"; "; ";
Id NAME
". $id." ". $name."
";

Previous page, next page

$pageprev = $page-1;

if ($page > $total) {

$pagenext = $total;

} else{

$pagenext = $page +1;

}

Do link jump;

echo "

Previous page 丨 next 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 丨 next page

";

These two points are the key to the art of paging technology and PHP code-

The above mentioned is this article to share all the content, I hope you can enjoy.

http://www.bkjia.com/PHPjc/1017139.html www.bkjia.com true http://www.bkjia.com/PHPjc/1017139.html techarticle PHP Paging function module share here to share is that the individual before the time did a list of the function module (PHP paging function module), very simple and practical, recommended to have ...

  • Related Article

    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.