php&mysql的翻页
<?php
// $conn=new mysqli('localhost','root','root','qiyewangzhan');
// $sql="select * from product";
// $res=$conn->query($sql);
// $list=$res->fetch_all(MYSQLI_ASSOC);
// $conn->close();
// 判断数据是否传输
$key = isset($_GET['key']) ? $_GET['key'] : '';
var_dump($key);
// 当前页码
$now = isset($_GET['now']) ? $_GET['now'] : 1;
// 每页显示的条数
$num = 3;
// 上一页
$sqla="select * from product where id=(select min(id) from product where id>$id)";
$res=$conn->query($sqla);
$pre=$res->fetch_assoc();
// 下一页
$sqlb="select * from product where id=(select max(id) from product where id<$id)";
$res=$conn->query($sqlb);
$next=$res->fetch_assoc();
// 排序的数据
$npage = ($now - 1) * $num . "," . $num;
// 获取数据库
$conn = new mysqli('localhost', 'root', 'root', 'qiyewangzhan');
$sql = "select * from product where title like '%$key%' limit $npage";
$res = $conn->query($sql);
$list = $res->fetch_all(MYSQLI_ASSOC);
// 总条数
$sql = "select * from product where title like '%$key%'";
$zongnum = $conn->query($sql);
$zongnum = $zongnum->num_rows;
// 总页码
$zpage = ceil($zongnum / $num);
$conn->close();
?>

posted on 2020-06-10 08:31 vermouthmo 阅读(244) 评论(0) 收藏 举报
浙公网安备 33010602011771号