时间:2021-07-01 10:21:17 帮助过:22人阅读
这是数据库查询的页面
include 'fenye.php';
header('content-type:text/html;charset=utf-8;');
$pdo=new PDO("mysql:host=localhost;dbname=t1","root","");
$stmt=$pdo->prepare("select * from jianzhi");
$stmt->execute();
$res=$stmt->fetchall();
$rows=count($res);//总的条数
$pagesize=8;//每页的条数
if($rows==0){
$pagenum=0;
}else{
$pagenum=ceil($rows/$pagesize);//分成几页
}
if(isset($_GET['page'])){
$page=$_GET['page'];
if(empty($page)||$page<0||!is_numeric($page)) {
$page=1;
}else{
$page=intval($page);
}
}else{
$page=1;
}
if($page>$pagenum){
$page=$pagenum;
}
$startnum = ($page - 1)*$pagesize;
$query = "SELECT * FROM blog LIMIT $startnum,$pagesize";
$stmt2=$pdo->prepare($query);
$stmt2->execute();
$res2=$stmt2->fetchall(PDO::FETCH_ASSOC);
看看这个就明白了http://www.imooc.com/learn/419