当前位置:Gxlcms > PHP教程 > PHP简单分页的实现

PHP简单分页的实现

时间:2021-07-01 10:21:17 帮助过:17人阅读

程序的关键点是页码的获取

query($allsql);    $field = $rest->fetch_fields();    $fieldNum = count($field);   //字段数量    //获取数据量    $rowNum = $rest->num_rows;    // echo "记录条数:".$rowNum;    $allpage=ceil($rowNum/$every);    // echo "----每页分$every"."条时有$allpage"."页
"; // $pageNow=($pageNow-1)*$every; echo ""; // echo "

测试信息表 添加

"; // echo "

$pageNow"."页

"; echo ""; for ($i=0; $i < $fieldNum; $i++) { echo ""; } echo ""; //显示分页 $sql="select * from $table limit $start,$every;"; // echo $sql; $newRest = $conn->query($sql); while($row = $newRest->fetch_row()){ echo ""; for ($j=0; $j <$fieldNum ; $j++) { echo ""; } echo ""; } echo "
".$field[$i]->name."
".$row[$j]."
"; echo ""; echo ""; echo "$pageNow/$allpage"; echo "首页"; if($pageNow==1){ echo "上一页"; }else{ $pagePre=$pageNow-1; echo "上一页"; } // echo "上一页"; // echo "下一页"; if($pageNow==$allpage){ echo "下一页"; }else{ $pageNext=$pageNow+1; // echo "

$pageNow

"; echo "下一页"; } echo "尾页"; echo "
"; echo ""; echo ""; echo "";$conn->close();}//实际使用一个测试数据表echo pagef(10,'test');?>

//css文件

*{padding: 0px;  margin: 0px;}.center{text-align: left;        color: red;        text-indent: 500px;}#info{color: DodgerBlue;}.table{       margin-left: auto;       margin-right: auto;       width: auto;       text-align: center;       color: royalblue;       border: 0;       }.td{width: 150px;    /*text-indent: 10px;*/    text-align: left;    font-size: 14px;}#td{color: #555;}tr:hover{background-color: DodgerBlue;}.info{text-align: center;      color: red;}.link{color: blue;      text-decoration: none;      text-align: center;      font-size: 12px;}.h3{text-align: center;    }#divclass{width: 100%;          height: 30px;          margin-top: 10px;          font-size: 18px;          /*background: coral;*/          }#center{width: 27%;        /*display: inline-block;*/        height: 30px;        margin-left: auto;        margin-right: auto;        /*background: orange;*/      }.fy{    /*background: DodgerBlue;*/    height: 30px;    line-height: 30px;    display: inline-block;    float: left;    color: DodgerBlue;    padding-left: 5px;    text-decoration: none;    text-align: center;   }.option{width: 80px;        height: 30px;        background: white;        float: left;        border: 2px solid DodgerBlue;        display: inline-block;}.button{width: 56px;        float: left;        color: white;        background: DodgerBlue;        height: 30px;        border: 0px;        border-radius: 0px;        display: inline-block;}

人气教程排行