php 漂亮的分页,php 原生php分页,漂亮的分页

效果:

66d260b049cfc33caaf47fce30711037.png

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 ){?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值