现在每一页的数据条数是两条
session_start();
require "conn.php";
// 判断是否登录
@session_start();
if(!isset($_SESSION['aname'])) {
header("location: login.php");die;
}
$cond = " where 1=1 ";
if(!empty($_POST['name'])) {
$name = $_POST['name'];
$cond .= " and name like '%{$name}%' ";
}
// 实现分页
$num = 2;
$res = mysqli_query($conn, "select count(*) as total from tushu $cond");
$row = mysqli_fetch_array($res);
$total = $row['total'];
if($total == 0) {
$pages = 1;
} else if($total % $num == 0) {
$pages = $total / $num;
} else {
$pages = (int)($total/$num) + 1;
}
// 获取当前页数
$page = isset($_GET['p']) ? $_GET['p'] : 1;
// 计算偏移量
$pianyi = ($page - 1) * $num;
$res = mysqli_query($conn, "select * from tushu $cond order by id desc limit $pianyi,$num");
?>
include "header.php"; ?>
<div class="fr righter">
<div class="title">
图书列表
div>
<table>
<tr>
<th>ISBNth>
<th>书名th>
<th>出版社th>
<th>存量th>
<th>位置th>
<th>操作th>
tr>
while($row = mysqli_fetch_array($res)): ?>
<tr>
<td> echo $row['isbn']; ?>td>
<td> echo $row['name']; ?>td>
<td> echo $row['chubanshe']; ?>td>
<td> echo $row['cunliang']; ?>td>
<td> echo $row['location']; ?>td>
<td>
if($_SESSION['role'] == "用户"):
?>
<a href='jieyue.php?id= echo $row['id']; ?>'><button>借阅<^tton>a>
endif; ?>
if($_SESSION['role'] == "管理员"):
?>
<a href='tushuEdit.php?id= echo $row['id']; ?>'><button>编辑<^tton>a>
<a href='tushuDel.php?id= echo $row['id']; ?>'><button>删除<^tton>a>
endif; ?>
td>
tr>
endWhile; ?>
<tr>
<td style="text-align: center;" colspan="6">
总条数目: echo $total; ?>
if($page != 1): ?>
<a href="./tushuList.php?p=1">首页a>
else: ?>
首页
endif; ?>
if($page != 1): ?>
<a href="./tushuList.php?p= echo $page-1; ?>">上一页a>
else: ?>
上一页
endif; ?>
if($page != $pages): ?>
<a href="./tushuList.php?p= echo $page+1; ?>">下一页a>
else: ?>
下一页
endif; ?>
if($page != $pages): ?>
<a href="./tushuList.php?p= echo $pages; ?>">尾页a>
else: ?>
尾页
endif; ?>
td>
tr>
table>
div>
// 实现分页
$num = 2; 这里改成4就可以了