Home > Backend Development > PHP Tutorial > How to implement paging display function of data in PHP

How to implement paging display function of data in PHP

墨辰丷
Release: 2023-03-29 12:26:02
Original
2321 people have browsed it

This article mainly introduces the data paging display function based on PHP in detail. Paging is a frequently used function in background management. Paging display facilitates the management of large amounts of data. Interested friends can refer to it

Implementation code:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>用户列表</title>
</head>
<body>
<?php 
  $con = mysql_connect("localhost","root","");
  
  mysql_query("set names utf8");
  mysql_select_db("zhiye",$con);
  
  $pageSize = 1;   //每页显示的数量
  $rowCount = 0;   //要从数据库中获取
  $pageNow = 1;    //当前显示第几页
  
  //如果有pageNow就使用,没有就默认第一页。
  if (!empty($_GET[&#39;pageNow&#39;])){
    $pageNow = $_GET[&#39;pageNow&#39;];
  }
  
  $pageCount = 0;  //表示共有多少页
  
  $sql1 = "select count(id) from user";
  $res1 = mysql_query($sql1);
  
  if($row1=mysql_fetch_row($res1)){
    $rowCount = $row1[0];
  }
  
  //计算共有多少页,ceil取进1
  $pageCount = ceil(($rowCount/$pageSize));
  
  //使用sql语句时,注意有些变量应取出赋值。
  $pre = ($pageNow-1)*$pageSize;
  
  $sql2 = "select * from user limit $pre,$pageSize";
  $res2 = mysql_query($sql2);
 
  while($row=mysql_fetch_assoc($res2)){
    echo $row[&#39;user_name&#39;]."<br>";
    echo $row[&#39;name&#39;]."<br>";
    echo $row[&#39;email&#39;]."<br>";
    echo $row[&#39;password&#39;]."<br>";
    echo $row[&#39;tel&#39;]."<br>";
  }
  for ($i=1;$i<=$pageCount;$i++){
    echo "<a href=&#39;userList.php?pageNow=$i&#39;>$i</a> ";
  }
?>
</body>
</html>
Copy after login

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's learning.

Related recommendations:

phpMethods to solve and avoid repeated form submission

PHP Detailed explanation of the implemented statistical data function

Sharing of two methods of converting PHP array encoding gbk and utf8 to and from each other

The above is the detailed content of How to implement paging display function of data in PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template