最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

PHP封裝的page分頁類定義與用法完整示例

 更新時間:2018年12月24日 10:26:10   作者:ChouCat  
這篇文章主要介紹了PHP封裝的page分頁類定義與用法,結(jié)合完整實例形式分析了php封裝的page分頁類具體定義、數(shù)據(jù)庫連接、查詢、樣式及調(diào)用等相關(guān)操作技巧,需要的朋友可以參考下

本文實例講述了PHP封裝的page分頁類定義與用法。分享給大家供大家參考,具體如下:

親測有效,見下圖=========>

1. 測試實例test.php

<?php
header("Content-Type: text/html; charset=utf-8");
date_default_timezone_set("Asia/Shanghai"); //時區(qū)
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>訂閱狀態(tài)</td>
          <td>商品狀態(tài)</td>
          <td>修改時間</td>
          <td>創(chuàng)建時間</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) {//總記錄數(shù)大于每頁顯示數(shù),顯示分頁
        $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>

2. 封裝的page分頁類page.class.php

<?php
/* * *********************************************
 * @類名:  page
 * @參數(shù):  $myde_total - 總記錄數(shù)
 *     $myde_size - 一頁顯示的記錄數(shù)
 *     $myde_page - 當(dāng)前頁
 *     $myde_url - 獲取當(dāng)前的url
 * @功能:  分頁實現(xiàn)
 */
class page {
  private $myde_total;     //總記錄數(shù)
  private $myde_size;      //一頁顯示的記錄數(shù)
  private $myde_page;      //當(dāng)前頁
  private $myde_page_count;   //總頁數(shù)
  private $myde_i;       //起頭頁數(shù)
  private $myde_en;       //結(jié)尾頁數(shù)
  private $myde_url;      //獲取當(dāng)前的url
  /*
   * $show_pages
   * 頁面顯示的格式,顯示鏈接的頁數(shù)為2*$show_pages+1。
   * 如$show_pages=2那么頁面上顯示就是[首頁] [上頁] 1 2 3 4 5 [下頁] [尾頁]
   */
  private $show_pages;
  public function __construct($myde_total = 1, $myde_size = 1, $myde_page = 1, $myde_url, $show_pages = 2) {
    $this->myde_total = $this->numeric($myde_total);
    $this->myde_size = $this->numeric($myde_size);
    $this->myde_page = $this->numeric($myde_page);
    $this->myde_page_count = ceil($this->myde_total / $this->myde_size);
    $this->myde_url = $myde_url;
    if ($this->myde_total < 0)
      $this->myde_total = 0;
    if ($this->myde_page < 1)
      $this->myde_page = 1;
    if ($this->myde_page_count < 1)
      $this->myde_page_count = 1;
    if ($this->myde_page > $this->myde_page_count)
      $this->myde_page = $this->myde_page_count;
    $this->limit = ($this->myde_page - 1) * $this->myde_size;
    $this->myde_i = $this->myde_page - $show_pages;
    $this->myde_en = $this->myde_page + $show_pages;
    if ($this->myde_i < 1) {
      $this->myde_en = $this->myde_en + (1 - $this->myde_i);
      $this->myde_i = 1;
    }
    if ($this->myde_en > $this->myde_page_count) {
      $this->myde_i = $this->myde_i - ($this->myde_en - $this->myde_page_count);
      $this->myde_en = $this->myde_page_count;
    }
    if ($this->myde_i < 1)
      $this->myde_i = 1;
  }
  //檢測是否為數(shù)字
  private function numeric($num) {
    if (strlen($num)) {
      if (!preg_match("/^[0-9]+$/", $num)) {
        $num = 1;
      } else {
        $num = substr($num, 0, 11);
      }
    } else {
      $num = 1;
    }
    return $num;
  }
  //地址替換
  private function page_replace($page) {
    return str_replace("{page}", $page, $this->myde_url);
  }
  //首頁
  private function myde_home() {
    if ($this->myde_page != 1) {
      return "<a href='" . $this->page_replace(1) . "' title='首頁'>首頁</a>";
    } else {
      return "<p>首頁</p>";
    }
  }
  //上一頁
  private function myde_prev() {
    if ($this->myde_page != 1) {
      return "<a href='" . $this->page_replace($this->myde_page - 1) . "' title='上一頁'>上一頁</a>";
    } else {
      return "<p>上一頁</p>";
    }
  }
  //下一頁
  private function myde_next() {
    if ($this->myde_page != $this->myde_page_count) {
      return "<a href='" . $this->page_replace($this->myde_page + 1) . "' title='下一頁'>下一頁</a>";
    } else {
      return"<p>下一頁</p>";
    }
  }
  //尾頁
  private function myde_last() {
    if ($this->myde_page != $this->myde_page_count) {
      return "<a href='" . $this->page_replace($this->myde_page_count) . "' title='尾頁'>尾頁</a>";
    } else {
      return "<p>尾頁</p>";
    }
  }
  //輸出
  public function myde_write($id = 'page') {
    $str = "<div id=" . $id . ">";
    $str.=$this->myde_home();
    $str.=$this->myde_prev();
    if ($this->myde_i > 1) {
      $str.="<p class='pageEllipsis'>...</p>";
    }
    for ($i = $this->myde_i; $i <= $this->myde_en; $i++) {
      if ($i == $this->myde_page) {
        $str.="<a href='" . $this->page_replace($i) . "' title='第" . $i . "頁' class='cur'>$i</a>";
      } else {
        $str.="<a href='" . $this->page_replace($i) . "' title='第" . $i . "頁'>$i</a>";
      }
    }
    if ($this->myde_en < $this->myde_page_count) {
      $str.="<p class='pageEllipsis'>...</p>";
    }
    $str.=$this->myde_next();
    $str.=$this->myde_last();
    $str.="<p class='pageRemark'>共<b>" . $this->myde_page_count .
        "</b>頁<b>" . $this->myde_total . "</b>條數(shù)據(jù)</p>";
    $str.="</div>";
    return $str;
  }
}
?>

3. css樣式

html, body, div, span, h1, h2, h3, h4, h5, h6, p, pre,
a, code, em, img, small, strong, sub, sup, u, i, center,
dl, dt, dd, ol, ul, li, fieldset, form, label {
  margin: 0;
  padding: 0;
  border: 0;
  outline: 0;
  font-size: 100%;
  vertical-align: baseline;
  background: transparent
}
a {
  color: #007bc4;
  text-decoration: none;
  cursor: pointer;
}
.table_parameters a:hover {
  text-decoration: none
}
a:hover {
  text-decoration: underline
}
ol, ul {
  list-style: none
}
table {
  border-collapse: collapse;
  border-spacing: 0
}
/*html {*/
/*background: url(../images/demo_bg.png)*/
/*}*/
body {
  height: 100%;
  font: 12px/18px "Microsoft Yahei", Tahoma, Helvetica,
  Arial, Verdana, "\5b8b\4f53", sans-serif;
  color: #51555c
}
img {
  border: 0;
  cursor: pointer;
}
.clearfix:after {
  visibility: hidden;
  display: block;
  font-size: 0;
  content: " ";
  clear: both;
  height: 0
}
.head {
  /*border-bottom: 1px solid #dadada;*/
  padding: 0 0 5px
}
.head_inner {
  margin: 0 auto;
  width: 980px
}
.container {
  width: 80%;
  /*min-height: 600px;*/
  margin: 30px auto 0 auto;
  border: 1px solid #d3d3d3;
  background: #fff;
  -moz-border-radius: 5px;
  -khtml-border-radius: 5px;
  -webkit-border-radius: 5px;
  border-radius: 5px
}
.demo > h2.title {
  margin: 4px 0 30px;
  padding: 15px 0 10px 20px;
  border-bottom: 1px solid #d3d3d3;
  font-size: 18px;
  color: #a84c10;
  background: url(../images/arrow.jpg) no-repeat 2px 14px
}
.foot {
  height: 60px;
  padding: 10px 2px;
  line-height: 24px;
  text-align: center
}
.foot a:hover {
  color: #51555c
}
.btn {
  -webkit-border-radius: 3px;
  -moz-border-radius: 3px;
  -ms-border-radius: 3px;
  -o-border-radius: 3px;
  border-radius: 3px;
  background-color: #ff8400;
  color: #fff;
  display: inline-block;
  height: 28px;
  line-height: 28px;
  text-align: center;
  padding: 0 12px;
  transition: background-color .2s linear 0s;
  border: 0;
  cursor: pointer
}
.btn:hover {
  background-color: #e95a00;
  text-decoration: none
}
.demo {
  width: 700px;
  margin: 0 auto
}
ul.ul_demo li {
  background: url("../images/demo_icon.gif") no-repeat scroll 0 6px;
  line-height: 28px;
  padding-left: 20px
}
.input, .table input[type='text'] {
  border: 1px solid #ccc;
  padding: 0 5px;
  width: 220px;
  height: 26px;
  line-height: 26px
}
#nav {
  float: right;
  margin: 30px 0 0
}
#nav li {
  float: left;
  font-size: 16px;
  margin-right: 20px
}
.btn.loading {
  opacity: .5
}
h3 a.cur {
  color: #f30;
}
.demo h3 a {
  font-size: 14px;
  margin: 0 10px 5px 0;
  display: inline-block
}
.red {
  color: red
}
.notice {
  font-size: 14px;
  margin-bottom: 10px;
}
.table_parameters {
  border-left: 1px solid #d3d3d3;
  border-top: 1px solid #d3d3d3;
  margin: 6px auto;
  font-size: 14px
}
.table_parameters tr.tr_head {
  background: none repeat scroll 0 0 #f7f7f7;
  font-weight: bold;
  padding: 6px;
  text-align: center
}
.table_parameters td, .table_parameters th {
  border-bottom: 1px solid #d3d3d3;
  border-right: 1px solid #d3d3d3;
  line-height: 26px;
  padding: 2px
}
h1 {
  font: 32px "Microsoft Yahei";
  margin: 40px auto;
  text-align: center;
}
h2 {
  font-size: 16px;
  margin: 10px 0;
}
.menu {
  height: 30px;
  margin-bottom: 30px;
  padding: 10px;
  background-color: #f0f0f0;
  text-align: center;
}
.menu a {
  display: inline-block;
  height: 30px;
  padding: 0 20px;
  line-height: 30px;
  font-size: 14px;
  color: #333;
  text-decoration: none;
}
.menu a:hover {
  color: #000;
  background-color: #e9e9e9;
}
.menu .cur {
  background-color: #ddd !important;
  color: #000;
}
.vad a {
  display: inline-block;
  height: 36px;
  line-height: 36px;
  margin: 0 5px;
  padding: 0 50px;
  font-size: 14px;
  text-align: center;
  color: #eee;
  text-decoration: none;
  background-color: #222;
}
.vad a:hover {
  color: #fff;
  background-color: #000;
}
.thead {
  width: 728px;
  height: 90px;
  margin: 0 auto;
}
textarea {
  border: 1px solid #ccc;
  font-size: 12px;
  height: 100px;
  line-height: 18px;
  padding: 5px;
  width: 300px;
}
.table td {
  padding: 10px 0
}
.disabled {
  opacity: .6;
  filter: alpha(opacity=60)
}
.demo > p {
  line-height: 30px;
  font-size: 14px
}
.demo > p a {
  font-size: 14px
}
.demo h3 {
  font-size: 16px;
  margin: 20px 0
}
select {
  background-color: #fff;
  background-position: right center;
  background-repeat: no-repeat;
  border: 1px solid #888;
  border-radius: 3px;
  box-sizing: border-box;
  font: 12px/1.5 Tahoma, Arial, sans-serif;
  height: 30px;
  padding: 0 4px;
}
fieldset {
  border: 1px solid #ccc;
  border-radius: 5px;
  margin: 1em 0;
  padding: 10px 20px;
}
dl.row dt {
  width: 2em;
}
dl.row dt {
  clear: left;
  float: left;
  line-height: 30px;
  padding: 5px;
  text-align: right;
  width: 6em;
}
dl.row dd {
  float: left;
  padding: 5px;
}
.pager {
  text-align: right;
}
.pager a {
  padding: 3px 8px;
  margin-left: 3px;
  line-height: 20px;
  background: #f9f9f9;
  border: 1px solid #DBDBDB;
  text-decoration: none
}
.pager a:hover,
.pager a.current {
  background-color: #7CD5B1;
  color: #fff;
  border: 1px solid #7CD5B1;
  cursor: pointer;
}
.page {
  text-align: center;
  margin: 50px 0
}
.page a, .page span.prev_disabled {
  border: 1px solid #ededed;
  color: #3d3d3d;
  font-weight: 700;
  height: 35px;
  line-height: 35px;
  margin-left: 5px;
  min-width: 9px;
  padding: 0 13px;
  text-align: center;
  text-decoration: none;
  vertical-align: top;
  font-family: "simsun";
  display: inline-block
}
.page span.prev_disabled {
  cursor: default;
  color: #ccc;
  margin: 0 10px 0 0
}
.page a.current {
  background-color: #f40;
  border-color: #f40;
  color: #fff;
  font-weight: 700;
  position: relative;
  z-index: 1;
}
.page .extra {
  display: inline-block;
  margin-left: 10px;
  height: 35px;
  line-height: 35px;
  color: #656565;
}
.page .page-num {
  border: 1px solid #ededed;
  height: 21px;
  text-align: center;
  width: 35px;
  display: inline-block
}
.page .page-submit {
  background-clip: padding-box;
  border: 1px solid #ededed;
  border-radius: 2px;
  cursor: pointer;
  height: 21px;
  line-height: 21px;
  text-align: center;
  width: 43px;
  display: inline-block
}
.page .page-submit:hover {
  border-color: #f40;
  color: #f40;
}
.page a:focus, .page a:hover {
  border-color: #f40;
  z-index: 1;
}
.loading {
  margin: 30px 0;
  text-align: center
}
p {
  margin: 0
}
#page {
  height: 40px;
  padding: 20px 0px;
}
#page a {
  display: block;
  float: left;
  margin-right: 10px;
  padding: 2px 12px;
  height: 24px;
  border: 1px #cccccc solid;
  background: #fff;
  text-decoration: none;
  color: #808080;
  font-size: 12px;
  line-height: 24px;
}
#page a:hover {
  color: #077ee3;
  border: 1px #077ee3 solid;
}
#page a.cur {
  border: none;
  background: #077ee3;
  color: #fff;
}
#page p {
  float: left;
  padding: 2px 12px;
  font-size: 12px;
  height: 24px;
  line-height: 24px;
  color: #bbb;
  border: 1px #ccc solid;
  background: #fcfcfc;
  margin-right: 8px;
}
#page p.pageRemark {
  border-style: none;
  background: none;
  margin-right: 0px;
  padding: 4px 0px;
  color: #666;
}
#page p.pageRemark b {
  color: red;
}
#page p.pageEllipsis {
  border-style: none;
  background: none;
  padding: 4px 0px;
  color: #808080;
}
.dates li {
  font-size: 14px;
  margin: 20px 0
}
.dates li span {
  text-align: center
}
td {
  font-size: 15px;
  margin: 20px 0
}

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php+mysql數(shù)據(jù)庫操作入門教程》、《php+mysqli數(shù)據(jù)庫程序設(shè)計技巧總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計入門教程》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》及《php常見數(shù)據(jù)庫操作技巧匯總

希望本文所述對大家PHP程序設(shè)計有所幫助。

相關(guān)文章

  • php異常:Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE  eval()''d code error

    php異常:Parse error: syntax error, unexpected T_ENCAPSED_AND_W

    PHP會出現(xiàn)eval()'d code error 錯誤提示的原因一般都是因為模板錯誤,原因有以下幾種情況
    2011-05-05
  • php實現(xiàn)陽歷陰歷互轉(zhuǎn)的方法

    php實現(xiàn)陽歷陰歷互轉(zhuǎn)的方法

    這篇文章主要介紹了php實現(xiàn)陽歷陰歷互轉(zhuǎn)的方法,同時還能獲取干支紀(jì)年,生肖,以及相應(yīng)的陰歷的中文叫法等,感興趣的小伙伴們可以參考一下
    2015-10-10
  • PHP+AJAX實現(xiàn)無刷新注冊(帶用戶名實時檢測)

    PHP+AJAX實現(xiàn)無刷新注冊(帶用戶名實時檢測)

    PHP+AJAX實現(xiàn)無刷新注冊(帶用戶名實時檢測)...
    2007-01-01
  • php 命名空間(namespace)原理與用法實例小結(jié)

    php 命名空間(namespace)原理與用法實例小結(jié)

    這篇文章主要介紹了php 命名空間(namespace)原理與用法,結(jié)合實例形式總結(jié)分析了PHP命名空間的相關(guān)概念、原理、基本使用方法及相關(guān)操作注意事項,需要的朋友可以參考下
    2019-11-11
  • php高性能日志系統(tǒng) seaslog 的安裝與使用方法分析

    php高性能日志系統(tǒng) seaslog 的安裝與使用方法分析

    這篇文章主要介紹了php高性能日志系統(tǒng) seaslog 的安裝與使用方法,結(jié)合實例形式分析了php日志系統(tǒng) seaslog 的安裝、配置、使用方法及相關(guān)注意事項,需要的朋友可以參考下
    2020-02-02
  • php精度計算的問題解析

    php精度計算的問題解析

    這篇文章主要介紹了php精度計算的問題解析,如果用php的+-*/計算浮點數(shù)的時候,可能會遇到一些計算結(jié)果錯誤的問題,比如上面 的 echo intval( 0.58*100 );會打印57,而不是58,需要的朋友可以參考下
    2019-06-06
  • PHP利用redis位圖實現(xiàn)簡單的簽到功能

    PHP利用redis位圖實現(xiàn)簡單的簽到功能

    在日常開發(fā)中, 我們會遇到需要存儲大量 bool類型數(shù)據(jù)的需求, 比如用戶簽到和用戶登陸的記錄等, 本文將為大家介紹如何利用redis位圖輕松實現(xiàn)簽到功能,感興趣的可以了解一下
    2023-06-06
  • JS實現(xiàn)php的偽分頁

    JS實現(xiàn)php的偽分頁

    假如某一個頁面的數(shù)據(jù)很多,不方便全都顯示出來,而且假設(shè)里面有個播放器,不希望在翻頁的時候播放器會終止的話,就可以采用這個方法盡管可以用Ajax,但是在數(shù)據(jù)比較少的情況下,這個方法更有優(yōu)勢
    2008-05-05
  • php 自定義錯誤日志實例詳解

    php 自定義錯誤日志實例詳解

    這篇文章主要介紹了php 自定義錯誤日志實例詳解的相關(guān)資料,需要的朋友可以參考下
    2016-11-11
  • php中限制ip段訪問、禁止ip提交表單的代碼分享

    php中限制ip段訪問、禁止ip提交表單的代碼分享

    在項目應(yīng)用中,我們經(jīng)常需要用到限制ip段訪問或者限制IP提交表單等等ip相關(guān)的功能,今天我來分享下本人所使用的這塊代碼,希望對大家有所幫助
    2014-08-08

最新評論

韶关市| 西贡区| 怀远县| 马龙县| 泰来县| 长治市| 历史| 琼海市| 临湘市| 拉孜县| 舟曲县| 天门市| 桐柏县| 河南省| 甘孜县| 澳门| 兴化市| 镇原县| 佳木斯市| 汨罗市| 通江县| 化州市| 长海县| 尤溪县| 新余市| 阿城市| 凉城县| 梁山县| 宁化县| 昆明市| 鹰潭市| 南丰县| 旌德县| 永兴县| 桃江县| 岳阳市| 鄯善县| 深圳市| 鹿泉市| 罗城| 沛县|