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 "".$field[$i]->name." | "; } 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 "".$row[$j]." | "; } echo "
"; } echo "
"; 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 "