php整体分页 上一页 下一页

php

浏览数:228

2019-1-13


核心代码,面向过程

<!DOCTYPE html>
<html>
<head>
    <meta charset=utf-8>
    <meta name=description content="">
    <meta name=viewport content="width=device-width, initial-scale=1">
    <title>雇员管理页面</title>
    <style>
        body{background:url('./images/bg.jpg');}
        .box{
            width:600px;
            height:600px;
            border:1px solid #ccc;
            margin:0 auto;
            padding:60px;
            box-sizing:border-box;
        }
         h1{text-align:center;}
        .page{text-decoration:none;padding:10px 10px;background:yellow;color:red;}
        form{margin-top:20px ;}
    </style>
</head>
<body>
<div class="box">
<h1>管理中心</h1>
<?php
    require_once 'rmpServer.class.php';
    require_once 'sqlHelper.class.php';

    $pagesize=3;  //
    $pagenow=1;  //现在是第几页
    $rowcount=0; //有多少条数据
    $pagecount=0;//页码数
    if(!empty($_GET['pagenow'])){
       $pagenow=($_GET['pagenow']);
    }

    $rmpServer=new rmpServer();
    $pagecount=$rmpServer->getPageCount($pagesize);
    $res2=$rmpServer->getListByPage($pagenow,$pagesize);

     if(!empty($_GET['flag'])){
       $id=$_GET['id'];
       $del=$rmpServer->deluser($id);
       if($del){
         echo "删除成功";
       }
    }
    echo "<table border='1' width='500'>";
    echo "<tr><th>id</th><th>name</th><th>password</th><th>操作1</th><th>操作2</th></tr>";

    // while($row=mysql_fetch_assoc($res2)){
    //     echo "<tr><td>{$row['id']}</td><td>{$row['name']}</td><td>{$row['password']}</td>
    //     <td><a href=''>删除</a></td><td><a href=''>修改</a></td></tr>";
    // }

    for($i=0;$i<count($res2);$i++){
       $row=$res2[$i];
        echo "<tr><td>{$row['id']}</td><td>{$row['name']}</td><td>{$row['password']}</td>
        <td><a href='rmp.php?flag=del&id={$row['id']}'>删除</a></td><td><a href=''>修改</a></td></tr>";
    }

    echo "</table>";
    echo "<br>";
    // for($i=1;$i<=$pagecount;$i++){
    //     echo "<a class='page' href='rmp.php?pagenow=$i '>$i</a>&nbsp;";
    // }
    if($pagenow>1){
        $prepage=$pagenow-1;
        echo "<a class='page' href='rmp.php?pagenow=$prepage'>上一页</a>&nbsp;";
    }

    if($pagenow<$pagecount){
        $nextpage=$pagenow+1;
        echo "<a class='page' href='rmp.php?pagenow=$nextpage'>下一页</a>&nbsp;";
    }
    echo "<br>";
    echo "<br>";
    echo "<br>";

    $page_whole=10;
    $star=floor(($pagenow-1)/$page_whole)*$page_whole+1;
    //1-10 20-20...控制页码 floor((n-1)/10)*10+1;
    $index=$star;
    //整体向前翻
    if($pagenow>$page_whole){
      echo "<a href='rmp.php?pagenow=".($star-1)."'><<<</a>&nbsp;";
    }

    //固定页面
    for(;$star<$index+$page_whole;$star++){
        echo "<a href='rmp.php?pagenow=$star'>[$star]</a>";
    }
    //整体向后翻
    echo "&nbsp;<a href='rmp.php?pagenow=$star'>>>>></a>";
    echo "<br>";
    echo "<br>";
    echo "<br>";
    echo "当前页{$pagenow}/总共{$pagecount}";

    // mysql_free_result($res2);
    // $sqlHelper->closeres();

?>

<form action="rmp.php" method="get" accept-charset="utf-8">
   跳转<input type="text" name="pagenow">
   <input type="submit" value="确定">
</form>
</div>

</body>
</html>