首页 > 开发 > PHP > 正文

PHP封装的page分页类定义与用法完整示例

2024-05-04 22:41:38
字体:
来源:转载
供稿:网友

本文实例讲述了PHP封装的page分页类定义与用法。分享给大家供大家参考,具体如下:

亲测有效,见下图=========>

1. 测试实例test.php

<?phpheader("Content-Type: text/html; charset=utf-8");date_default_timezone_set("Asia/Shanghai"); //时区require_once('page.class.php');$showrow = 5;$curpage = empty($_GET['page']) ? 1 : $_GET['page'];$url = "?page={page}";$dsn = 'mysql:host=xxx.xxx.80.xxx;dbname=admin';$pdo = new PDO($dsn, 'root', 'root');$pdo->query('set names utf8');$sql = "SELECT * from operator_list where 1=1";$res_gg = $pdo->query("SELECT count(*) as ctn from operator_list where 1=1;");$result = $res_gg->fetch();$total = $result["ctn"];if (!empty($_GET['page']) && $total != 0 && $curpage > ceil($total / $showrow)) {  $curpage = ceil($total_rows / $showrow);}$sql .= " LIMIT " . ($curpage - 1) * $showrow . ",$showrow;";$res_zz = $pdo->query($sql);$result = $res_zz->fetchAll();//print_r(json_encode($result));die;?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head>  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>  <title></title>  <meta name="keywords" content="入库"/>  <meta name="description" content="入库"/>  <script type="text/javascript" src="static/js/jquery-1.11.0.min.js?v=1"></script>  <link rel="stylesheet" type="text/css" href="static/css/common.css" rel="external nofollow" /></head><body><div class="head">  <!--  <div class="head_inner clearfix">-->  <!--    <ul id="nav">-->  <!--      <li><a href="javascript;" rel="external nofollow" rel="external nofollow" >商品列表</a></li>-->  <!--      <li><a href="javascript;" rel="external nofollow" rel="external nofollow" >详情列表</a></li>-->  <!--    </ul>-->  <!--        <a class="logo" href="javascript" rel="external nofollow" >            <img src="javascript;" alt="公司logo" /></a> -->  <!--  </div>--></div><div class="container">  <div class="demo">    <h2 class="title">报表</h2>    <div class="showData">      <table width="100%" border="0" align="center"      style="border:1px solid #ccc;" cellpadding="0" cellspacing="1">        <tr align="center">          <td>ID</td>          <td>商品编号</td>          <td>订阅状态</td>          <td>商品状态</td>          <td>修改时间</td>          <td>创建时间</td>        </tr>        <?php        if (!empty($result)) {          foreach ($result as $k => $v) {            ?>            <tr align="center">              <td><?php echo $v['id']; ?></td>              <td><?php echo $v["customer_id"]; ?></td>              <td><?php echo $v["name"]; ?></td>              <td><?php echo $v["role_id"]; ?></td>              <td><?php echo $v["status"]; ?></td>              <td><?php echo $v["cdate"]; ?></td>            </tr>            <?php          }        }        ?>      </table>    </div>    <div class="showPage">      <?php      if ($total > $showrow) {//总记录数大于每页显示数,显示分页        $page = new page($total, $showrow, $curpage, $url, 3);        echo $page->myde_write();      }      ?>    </div>  </div></div><div class="foot">  阿里巴巴:<a href="#" rel="external nofollow" target="_blank">https://www.taobao.com</a></div></body></html>            
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表