效果:
1、php分页方法
function page($count,$listRows,$curPage,$rowsmaxPage =null,$search=null){
$search = isset($search)?$search:"";
$rowsmaxPage = isset($rowsmaxPage)?$rowsmaxPage:10;
$totalpage =ceil($count/$listRows);
//存储页码字符串
$pageNumString = "";
if($curPage <=($rowsmaxPage/2)){
$begin =1;
$end = $totalpage>=$rowsmaxPage?$rowsmaxPage:$totalpage;
}else{
$end = $curPage +($rowsmaxPage/2)>$totalpage?$totalpage:$curPage +($rowsmaxPage/2);
$begin =$end -$rowsmaxPage-1<=1?1:$end -$rowsmaxPage-1;
}
//实现上一页
$prev = $curPage -1<=1?1:$curPage -1;
$pageNumString .="
".$count." Record ".$curPage."/".$totalpage." PAGE";
$pageNumString .="
2、跳页,js
//js片段代码
function jumpPage(){
var curPage = document.getElementsByClassName("jump")[0].value;
var maxpage = document.getElementById("max").value;
if(isNaN(curPage) || Number(curPage)<1){
curPage = 1;
}
if(Number(curPage)>Number(maxpage)){
curPage = maxpage;
if(curPage==0){
curPage=1;
}
}
window.location="?curPage="+curPage+"&search=";
}
3、css代码片段
.page {
text-align: center;
}
.page li {
display: inline;
}
.page li a {
color: black;
padding: 6px 8px;
text-decoration: none;
transition: background-color .3s;
border: 1px solid #ddd;
margin: 2px;
border-radius: 2px;
}
ul.page li .active {
background-color: #4CAF50;
color: white;
border: 1px solid #4CAF50;
display: inline-flex;
}
ul.page li a:hover:not(.active) {
background-color: #ddd;
}
.jump{
width: 30px;
margin-left: 5px;
height: 27px;
border: 1px solid #ccc;
border-radius: 3px;
}
.jump:focus{
border: solid 1px #0f9ae0;
}
总结:
1、修改数据库链接
2、修改表的名称
3、修改字段
直接运行
total;
}
//分页数据
function data($sql){
$link=con();
$result = mysqli_query($link,$sql); //获取所有的数据
$arr=array();
while($t_result = mysqli_fetch_array($result,MYSQLI_ASSOC)){
$arr[]=$t_result;
}
mysqli_free_result($result);
mysqli_close($link);
return $arr;
}
function page($count,$listRows,$curPage,$rowsmaxPage =null,$search=null){
$search = isset($search)?$search:"";
$rowsmaxPage = isset($rowsmaxPage)?$rowsmaxPage:10;
$totalpage =ceil($count/$listRows);
//存储页码字符串
$pageNumString = "";
if($curPage <=($rowsmaxPage/2)){
$begin =1;
$end = $totalpage>=$rowsmaxPage?$rowsmaxPage:$totalpage;
}else{
$end = $curPage +($rowsmaxPage/2)>$totalpage?$totalpage:$curPage +($rowsmaxPage/2);
$begin =$end -$rowsmaxPage-1<=1?1:$end -$rowsmaxPage-1;
}
//实现上一页
$prev = $curPage -1<=1?1:$curPage -1;
$pageNumString .="
".$count." Record ".$curPage."/".$totalpage." PAGE";
$pageNumString .="
文章列表
食品
search
$vo ){?>