程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> php實戰第八天

php實戰第八天

編輯:關於PHP編程

今天是學習做後台頁面布局,用得是bootcss。那麼效果展示一下。

 

 

\\

 

 


布局的代碼


[html]  <!DOCTYPE html> 
<html lang="en"> 
<head> 
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
  <title>無標題文檔</title> 
  <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"></head> 
 
<body> 
 
  <div class="container-fluid"> 
    <div class="row-fluid"> 
      <div class="span4"> 
        <h3>瀑布流留言板管理系統</h3> 
      </div> 
    </div> 
 
    <div class="row-fluid"> 
      <div id="menu" class="span2"> 
        <ul class="nav nav-list"> 
          <li class="nav-header">留言管理</li> 
          <li class="active"> 
            <a id="start" href="javascript:void(0);">所有留言</a> 
          </li> 
          <li class="nav-header">網站管理</li> 
          <li class=""> 
            <a href="javascript:void(0);">基本設置</a> 
          </li> 
 
        </ul> 
      </div> 
 
      <div id="main" class="span10"> 
        <div id="mainData"></div> 
      </div> 
    </div> 
 
  </div> 
 
</body> 
  <script src="js/jquery-2.0.1.min.js"></script> 
 
  <script type="text/javascript" src="js/bootstrap.min.js"></script> 
  <script type="text/javascript" src="js/admin.js"></script> 
 
</html> 

<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>無標題文檔</title>
  <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"></head>

<body>

  <div class="container-fluid">
    <div class="row-fluid">
      <div class="span4">
        <h3>瀑布流留言板管理系統</h3>
      </div>
    </div>

    <div class="row-fluid">
      <div id="menu" class="span2">
        <ul class="nav nav-list">
          <li class="nav-header">留言管理</li>
          <li class="active">
            <a id="start" href="javascript:void(0);">所有留言</a>
          </li>
          <li class="nav-header">網站管理</li>
          <li class="">
            <a href="javascript:void(0);">基本設置</a>
          </li>

        </ul>
      </div>

      <div id="main" class="span10">
        <div id="mainData"></div>
      </div>
    </div>

  </div>

</body>
  <script src="js/jquery-2.0.1.min.js"></script>

  <script type="text/javascript" src="js/bootstrap.min.js"></script>
  <script type="text/javascript" src="js/admin.js"></script>

</html>

 

 


從中學到javascript函數

str.substr(0,20)意思是從0個字符開始取20個字符

Math.random()取隨機數

switch語句

 

 

這後台是ajax的噢。寫了好久的分頁呢。好吧,直接上代碼。

[javascript]  // JavaScript Document  
$('body').off('.data-api'); 
 
$(document).ready(function(e) { 
 
    $("#menu a").click(function() { 
 
        switch ($(this).text()) { 
            case '所有留言': 
                admin_content(1); 
                break; 
 
            case '基本設置': 
                $("#main #mainData").load('admin_config.html?r='+Math.random()); 
                break; 
 
            default: 
                break; 
        } 
 
 
 
    }); 
 
    $("#start").click(); 
}); 
 
 
/**
*留言管理
*/ 
function admin_content(page) { 
    $.ajax({ 
        url: 'http://localhost/l/admin.php?m=admin&a=content&page=' + page + '&rand=' + Math.random(), 
        type: 'get', 
        dataType: 'json', 
        data: {}, 
        complete: function(xhr, textStatus) { 
            //called when complete  
        }, 
        success: function(json, textStatus, xhr) { 
            if (json['state'] == 'ok') { 
                var page_start = json['start'];//分頁開始  
                var page_end = json['end'];//分頁結束  
                var page_page = json['page'];//分頁當前頁面  
                var data = json['data'];//分頁數據  
/**
* 生成 表格內容
*/ 
                var table_html = '<table class="table table-hover"><tr><th>操作</th><th>用戶名</th><th>留言內容</th><th>發表時間</th></tr>'; 
                for (i = 0; i < data.length; i++) { 
                    var trClass = (i % 2 == 0) ? 'class="info"' : ''; 
 
                    var tr_html = '<tr ' + trClass + '><td width=100><a href="javascript:admin_content_del('+data[i].id+');">刪除</a></td><td width=100>' + data[i].userName + '</td><td width=400 ><div style="max-width:400px;max-height:150px;overflow-y:auto;">' + data[i].content + '</div></td><td >' + getLocalTime(data[i].time) + '</td></tr>'; 
                    table_html = table_html + tr_html; 
                } 
                table_html = table_html + '</table>'; 
 
/**
*生成分頁
*/ 
                var page_html = '<div id="mainPage"><div class="pagination"><ul>'; 
                if (page_end !== 0) { 
                    if (page_page == 1) { 
                        page_html = page_html + '<li class="disabled"><a href="JavaScript:void(0);">«</a></li>'; 
                    } else { 
                        page_html = page_html + '<li><a href="JavaScript:void(0);">«</a></li>'; 
                    } 
                } 
                for (var i = page_start; i <= page_end; i++) { 
                    if (page_page == i) { 
                        page_html = page_html + '<li class="active"><a href="JavaScript:void(0);">' + i + '</a></li>'; 
                    } else { 
                        page_html = page_html + '<li><a href="JavaScript:void(0);">' + i + '</a></li>'; 
                    } 
 
                } 
                if (page_end !== 0) { 
                    if (page_page == page_end) { 
                        page_html = page_html + '<li class="disabled"><a href="JavaScript:void(0);">»</a></li>'; 
                    } else { 
                        page_html = page_html + '<li><a href="JavaScript:void(0);">»</a></li>'; 
                    } 
 
                } 
                page_html = page_html + '</ul></div></div>'; 
 
 
                var mainData = $("#main #mainData"); 
                mainData.html(table_html); 
                mainData.append(page_html); 
 
                admin_content_page(page_page,page_end); //掛接分頁點擊事件  
            } 
 
 
 
            //alert(json.data);  
        }, 
        error: function(xhr, textStatus, errorThrown) { 
            //called when there is an error  
        } 
    }); 

 
/**
* 掛機分頁事件
* 參數 page_page 當前分頁
* 參數 page_end  分頁數量
*/ 
function admin_content_page(page_page,page_end) { 
    $("#mainPage a").click(function() { 
        var charStr = $(this).text(); 
        var num = charStr; 
        if (charStr == "»") { 
            num = parseInt(page_page) + 1; 
            if (page_end < num) { 
                return; 
            } 
 
        } else if (charStr == "«") { 
            num = parseInt(page_page) - 1; 
            if (num <= 0) { 
                return; 
            } 
        } 
 
        admin_content(num); 
 
    }); 

 
function admin_content_del (id) { 
    alert(id); 

 
function getLocalTime(nS) { 
    return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/, ' '); 

// JavaScript Document
$('body').off('.data-api');

$(document).ready(function(e) {

 $("#menu a").click(function() {

  switch ($(this).text()) {
   case '所有留言':
    admin_content(1);
    break;

   case '基本設置':
    $("#main #mainData").load('admin_config.html?r='+Math.random());
    break;

   default:
    break;
  }

 

 });

 $("#start").click();
});


/**
*留言管理
*/
function admin_content(page) {
 $.ajax({
  url: 'http://localhost/l/admin.php?m=admin&a=content&page=' + page + '&rand=' + Math.random(),
  type: 'get',
  dataType: 'json',
  data: {},
  complete: function(xhr, textStatus) {
   //called when complete
  },
  success: function(json, textStatus, xhr) {
   if (json['state'] == 'ok') {
    var page_start = json['start'];//分頁開始
    var page_end = json['end'];//分頁結束
    var page_page = json['page'];//分頁當前頁面
    var data = json['data'];//分頁數據
/**
* 生成 表格內容
*/
    var table_html = '<table class="table table-hover"><tr><th>操作</th><th>用戶名</th><th>留言內容</th><th>發表時間</th></tr>';
    for (i = 0; i < data.length; i++) {
     var trClass = (i % 2 == 0) ? 'class="info"' : '';

     var tr_html = '<tr ' + trClass + '><td width=100><a href="javascript:admin_content_del('+data[i].id+');">刪除</a></td><td width=100>' + data[i].userName + '</td><td width=400 ><div style="max-width:400px;max-height:150px;overflow-y:auto;">' + data[i].content + '</div></td><td >' + getLocalTime(data[i].time) + '</td></tr>';
     table_html = table_html + tr_html;
    }
    table_html = table_html + '</table>';

/**
*生成分頁
*/
    var page_html = '<div id="mainPage"><div class="pagination"><ul>';
    if (page_end !== 0) {
     if (page_page == 1) {
      page_html = page_html + '<li class="disabled"><a href="JavaScript:void(0);">«</a></li>';
     } else {
      page_html = page_html + '<li><a href="JavaScript:void(0);">«</a></li>';
     }
    }
    for (var i = page_start; i <= page_end; i++) {
     if (page_page == i) {
      page_html = page_html + '<li class="active"><a href="JavaScript:void(0);">' + i + '</a></li>';
     } else {
      page_html = page_html + '<li><a href="JavaScript:void(0);">' + i + '</a></li>';
     }

    }
    if (page_end !== 0) {
     if (page_page == page_end) {
      page_html = page_html + '<li class="disabled"><a href="JavaScript:void(0);">»</a></li>';
     } else {
      page_html = page_html + '<li><a href="JavaScript:void(0);">»</a></li>';
     }

    }
    page_html = page_html + '</ul></div></div>';


    var mainData = $("#main #mainData");
    mainData.html(table_html);
    mainData.append(page_html);

    admin_content_page(page_page,page_end); //掛接分頁點擊事件
   }

 

   //alert(json.data);
  },
  error: function(xhr, textStatus, errorThrown) {
   //called when there is an error
  }
 });
}

/**
* 掛機分頁事件
* 參數 page_page 當前分頁
* 參數 page_end  分頁數量
*/
function admin_content_page(page_page,page_end) {
 $("#mainPage a").click(function() {
  var charStr = $(this).text();
  var num = charStr;
  if (charStr == "»") {
   num = parseInt(page_page) + 1;
   if (page_end < num) {
    return;
   }

  } else if (charStr == "«") {
   num = parseInt(page_page) - 1;
   if (num <= 0) {
    return;
   }
  }

  admin_content(num);

 });
}

function admin_content_del (id) {
 alert(id);
}

function getLocalTime(nS) {
 return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/, ' ');
}這是分頁請求的服務端代碼


[php]  public function content() 

    //引入分頁類  
    include "page.class.php"; 
        //得到data表的數據數量  
    $rows = $this->db->count('select * from data'); 
    //創建分頁對象  
    $page = new Page($rows, 5, ""); 
    $list=$this->db 
           ->order('id DESC') 
           ->table('data') 
           ->limit($page->getLimit()) 
           ->select(); 
    /*
    echo "<pre>";
    var_dump($list);
    echo "</pre>";
    */ 
    $json['state']='ok'; 
    $json['start']=$page->getStart(); 
    $json['end']=$page->getEnd(); 
    $json['page']=$page->getPage(); 
    $json['data']=$list; 
    echo json_encode($json); 
    //exit();  

  public function content()
  {
   //引入分頁類
   include "page.class.php";
    //得到data表的數據數量
   $rows = $this->db->count('select * from data');
   //創建分頁對象
   $page = new Page($rows, 5, "");
   $list=$this->db
       ->order('id DESC')
       ->table('data')
        ->limit($page->getLimit())
        ->select();
   /*
   echo "<pre>";
   var_dump($list);
   echo "</pre>";
   */
   $json['state']='ok';
   $json['start']=$page->getStart();
   $json['end']=$page->getEnd();
   $json['page']=$page->getPage();
   $json['data']=$list;
   echo json_encode($json);
   //exit();
  }
做這分頁的時候由於是ajax,html代碼生成都在客戶端。經過我觀察這分頁類存在問題。實際上許多代碼都沒必要存在。有時間我去把他干掉。

附上代碼 page.class.php

 

 

[php]  <?php 
    /**
        file: page.class.php 
        完美分頁類 Page 
        @微涼 QQ496928838
    */ 
    class Page { 
        private $total;                         //數據表中總記錄數  
        private $listRows;                      //每頁顯示行數  
        private $limit;                         //SQL語句使用limit從句,限制獲取記錄個數  
        private $uri;                           //自動獲取url的請求地址  
        private $pageNum;                       //總頁數  
        private $page;                          //當前頁     
        private $config = array( 
                            'head' => "條記錄",  
                            'prev' => "上一頁",  
                            'next' => "下一頁",  
                            'first'=> "首頁",  
                            'last' => "末頁" 
                        );                      //在分頁信息中顯示內容,可以自己通過set()方法設置  
        private $listNum = 10;                  //默認分頁列表顯示的個數  
 
        /**
            構造方法,可以設置分頁類的屬性
            @param  int $total      計算分頁的總記錄數
            @param  int $listRows   可選的,設置每頁需要顯示的記錄數,默認為25條
            @param  mixed   $query  可選的,為向目標頁面傳遞參數,可以是數組,也可以是查詢字符串格式
            @param  bool    $ord    可選的,默認值為true, 頁面從第一頁開始顯示,false則為最後一頁
         */ 
        public function __construct($total, $listRows=25, $query="", $ord=true){ 
            $this->total = $total; 
            $this->listRows = $listRows; 
            $this->uri = $this->getUri($query); 
            $this->pageNum = ceil($this->total / $this->listRows); 
            /*以下判斷用來設置當前面*/ 
            if(!empty($_GET["page"])) { 
                $page = $_GET["page"]; 
            }else{ 
                if($ord) 
                    $page = 1; 
                else 
                    $page = $this->pageNum; 
            } 
 
            if($total > 0) { 
                if(preg_match('/\D/', $page) ){ 
                    $this->page = 1; 
                }else{ 
                    $this->page = $page; 
                } 
            }else{ 
                $this->page = 0; 
            } 
             
            $this->limit = "LIMIT ".$this->getLimit(); 
        } 
 
        /**
            用於設置顯示分頁的信息,可以進行連貫操作
            @param  string  $param  是成員屬性數組config的下標
            @param  string  $value  用於設置config下標對應的元素值
            @return object          返回本對象自己$this, 用於連慣操作
         */ 
        function set($param, $value){ 
            if(array_key_exists($param, $this->config)){ 
                $this->config[$param] = $value; 
            } 
            return $this; 
        } 
         
        /* 不是直接去調用,通過該方法,可以使用在對象外部直接獲取私有成員屬性limit和page的值 */ 
        function __get($args){ 
            if($args == "limit" || $args == "page") 
                return $this->$args; 
            else 
                return null; 
        } 
         
        /**
            按指定的格式輸出分頁
            @param  int 0-7的數字分別作為參數,用於自定義輸出分頁結構和調整結構的順序,默認輸出全部結構
            @return string  分頁信息內容
         */ 
        function fpage(){ 
            $arr = func_get_args(); 
 
            $html[0] = " 共<b> {$this->total} </b>{$this->config["head"]} "; 
            $html[1] = " 本頁 <b>".$this->disnum()."</b> 條 "; 
            $html[2] = " 本頁從 <b>{$this->start()}-{$this->end()}</b> 條 "; 
            $html[3] = " <b>{$this->page}/{$this->pageNum}</b>頁 "; 
            $html[4] = $this->firstprev(); 
            $html[5] = $this->pageList(); 
            $html[6] = $this->nextlast(); 
            $html[7] = $this->goPage(); 
 
            $fpage = '<div style="font:12px \'\5B8B\4F53\',san-serif;">'; 
            if(count($arr) < 1) 
                $arr = array(0, 1,2,3,4,5,6,7); 
                 
            for($i = 0; $i < count($arr); $i++) 
                $fpage .= $html[$arr[$i]]; 
         
            $fpage .= '</div>'; 
            return $fpage; 
        } 
         
        /* 格式為 1,5,*/ 
        function getLimit(){ 
            if($this->page > 0) 
                return ($this->page-1)*$this->listRows.",{$this->listRows}"; 
            else 
                return 0; 
        } 
 
        //當前的頁面  
        function getPage(){ 
            return $this->page; 
        } 
        //分頁的開始  
        function getStart(){ 
            $num1=$this->page-4; 
 
            return $num1>0?$num1:1; 
 
        } 
        //分頁的結束  
        function getEnd(){ 
            $num1=$this->pageNum; 
            $num2=$this->page+5; 
 
            return $num1<$num2?$num1:$num2; 
        } 
 
        /* 在對象內部使用的私有方法,用於自動獲取訪問的當前URL */ 
        private function getUri($query){     
            $request_uri = $_SERVER["REQUEST_URI"];  
            $url = strstr($request_uri,'?') ? $request_uri :  $request_uri.'?'; 
             
            if(is_array($query)) 
                $url .= http_build_query($query); 
            else if($query != "") 
                $url .= "&".trim($query, "?&"); 
         
            $arr = parse_url($url); 
 
            if(isset($arr["query"])){ 
                parse_str($arr["query"], $arrs); 
                unset($arrs["page"]); 
                $url = $arr["path"].'?'.http_build_query($arrs); 
            } 
             
            if(strstr($url, '?')) { 
                if(substr($url, -1)!='?') 
                    $url = $url.'&'; 
            }else{ 
                $url = $url.'?'; 
            } 
             
            return $url; 
        } 
 
        /* 在對象內部使用的私有方法,用於獲取當前頁開始的記錄數 */ 
        private function start(){ 
            if($this->total == 0) 
                return 0; 
            else 
                return ($this->page-1) * $this->listRows+1; 
        } 
 
        /* 在對象內部使用的私有方法,用於獲取當前頁結束的記錄數 */ 
        private function end(){ 
            return min($this->page * $this->listRows, $this->total); 
        } 
 
        /* 在對象內部使用的私有方法,用於獲取上一頁和首頁的操作信息 */ 
        private function firstprev(){ 
            if($this->page > 1) { 
                $str = " <a href='{$this->uri}page=1'>{$this->config["first"]}</a> "; 
                $str .= "<a href='{$this->uri}page=".($this->page-1)."'>{$this->config["prev"]}</a> ";         
                return $str; 
            } 
 
        } 
     
        /* 在對象內部使用的私有方法,用於獲取頁數列表信息 */ 
        private function pageList(){ 
            $linkPage = " <b>"; 
             
            $inum = floor($this->listNum/2); 
            /*當前頁前面的列表 */ 
            for($i = $inum; $i >= 1; $i--){ 
                $page = $this->page-$i; 
 
                if($page >= 1) 
                    $linkPage .= "<a href='{$this->uri}page={$page}'>{$page}</a> "; 
            } 
            /*當前頁的信息 */ 
            if($this->pageNum > 1) 
                $linkPage .= "<span style='padding:1px 2px;background:#BBB;color:white'>{$this->page}</span> "; 
             
            /*當前頁後面的列表 */ 
            for($i=1; $i <= $inum; $i++){ 
                $page = $this->page+$i; 
                if($page <= $this->pageNum) 
                    $linkPage .= "<a href='{$this->uri}page={$page}'>{$page}</a> "; 
                else 
                    break; 
            } 
            $linkPage .= '</b>'; 
            return $linkPage; 
        } 
 
        /* 在對象內部使用的私有方法,獲取下一頁和尾頁的操作信息 */ 
        private function nextlast(){ 
            if($this->page != $this->pageNum) { 
                $str = " <a href='{$this->uri}page=".($this->page+1)."'>{$this->config["next"]}</a> "; 
                $str .= " <a href='{$this->uri}page=".($this->pageNum)."'>{$this->config["last"]}</a> "; 
                return $str; 
            } 
        } 
 
        /* 在對象內部使用的私有方法,用於顯示和處理表單跳轉頁面 */ 
        private function goPage(){ 
                if($this->pageNum > 1) { 
                return ' <input style="width:20px;height:17px !important;height:18px;border:1px solid #CCCCCC;" type="text" onkeydown="javascript:if(event.keyCode==13){var page=(this.value>'.$this->pageNum.')?'.$this->pageNum.':this.value;location=\''.$this->uri.'page=\'+page+\'\'}" value="'.$this->page.'"><input style="cursor:pointer;width:25px;height:18px;border:1px solid #CCCCCC;" type="button" value="GO" onclick="javascript:var page=(this.previousSibling.value>'.$this->pageNum.')?'.$this->pageNum.':this.previousSibling.value;location=\''.$this->uri.'page=\'+page+\'\'"> '; 
            } 
        } 
 
        /* 在對象內部使用的私有方法,用於獲取本頁顯示的記錄條數 */ 
        private function disnum(){ 
            if($this->total > 0){ 
                return $this->end()-$this->start()+1; 
            }else{ 
                return 0; 
            } 
        } 
    } 
 
     
     
     

<?php
 /**
  file: page.class.php
  完美分頁類 Page
  @微涼 QQ496928838
 */
 class Page {
  private $total;          //數據表中總記錄數
  private $listRows;       //每頁顯示行數
  private $limit;          //SQL語句使用limit從句,限制獲取記錄個數
  private $uri;            //自動獲取url的請求地址
  private $pageNum;        //總頁數
  private $page;       //當前頁 
  private $config = array(
       'head' => "條記錄",
       'prev' => "上一頁",
       'next' => "下一頁",
       'first'=> "首頁",
       'last' => "末頁"
      );       //在分頁信息中顯示內容,可以自己通過set()方法設置
  private $listNum = 10;      //默認分頁列表顯示的個數

  /**
   構造方法,可以設置分頁類的屬性
   @param int $total  計算分頁的總記錄數
   @param int $listRows 可選的,設置每頁需要顯示的記錄數,默認為25條
   @param mixed $query 可選的,為向目標頁面傳遞參數,可以是數組,也可以是查詢字符串格式
   @param  bool $ord 可選的,默認值為true, 頁面從第一頁開始顯示,false則為最後一頁
   */
  public function __construct($total, $listRows=25, $query="", $ord=true){
   $this->total = $total;
   $this->listRows = $listRows;
   $this->uri = $this->getUri($query);
   $this->pageNum = ceil($this->total / $this->listRows);
   /*以下判斷用來設置當前面*/
   if(!empty($_GET["page"])) {
    $page = $_GET["page"];
   }else{
    if($ord)
     $page = 1;
    else
     $page = $this->pageNum;
   }

   if($total > 0) {
    if(preg_match('/\D/', $page) ){
     $this->page = 1;
    }else{
     $this->page = $page;
    }
   }else{
    $this->page = 0;
   }
   
   $this->limit = "LIMIT ".$this->getLimit();
  }

  /**
   用於設置顯示分頁的信息,可以進行連貫操作
   @param string $param 是成員屬性數組config的下標
   @param string $value 用於設置config下標對應的元素值
   @return object   返回本對象自己$this, 用於連慣操作
   */
  function set($param, $value){
   if(array_key_exists($param, $this->config)){
    $this->config[$param] = $value;
   }
   return $this;
  }
  
  /* 不是直接去調用,通過該方法,可以使用在對象外部直接獲取私有成員屬性limit和page的值 */
  function __get($args){
   if($args == "limit" || $args == "page")
    return $this->$args;
   else
    return null;
  }
  
  /**
   按指定的格式輸出分頁
   @param int 0-7的數字分別作為參數,用於自定義輸出分頁結構和調整結構的順序,默認輸出全部結構
   @return string 分頁信息內容
   */
  function fpage(){
   $arr = func_get_args();

   $html[0] = " 共<b> {$this->total} </b>{$this->config["head"]} ";
   $html[1] = " 本頁 <b>".$this->disnum()."</b> 條 ";
   $html[2] = " 本頁從 <b>{$this->start()}-{$this->end()}</b> 條 ";
   $html[3] = " <b>{$this->page}/{$this->pageNum}</b>頁 ";
   $html[4] = $this->firstprev();
   $html[5] = $this->pageList();
   $html[6] = $this->nextlast();
   $html[7] = $this->goPage();

   $fpage = '<div style="font:12px \'\5B8B\4F53\',san-serif;">';
   if(count($arr) < 1)
    $arr = array(0, 1,2,3,4,5,6,7);
    
   for($i = 0; $i < count($arr); $i++)
    $fpage .= $html[$arr[$i]];
  
   $fpage .= '</div>';
   return $fpage;
  }
  
  /* 格式為 1,5,*/
  function getLimit(){
   if($this->page > 0)
    return ($this->page-1)*$this->listRows.",{$this->listRows}";
   else
    return 0;
  }

  //當前的頁面
  function getPage(){
   return $this->page;
  }
  //分頁的開始
  function getStart(){
   $num1=$this->page-4;

   return $num1>0?$num1:1;

  }
  //分頁的結束
  function getEnd(){
   $num1=$this->pageNum;
   $num2=$this->page+5;

   return $num1<$num2?$num1:$num2;
  }

  /* 在對象內部使用的私有方法,用於自動獲取訪問的當前URL */
  private function getUri($query){ 
   $request_uri = $_SERVER["REQUEST_URI"]; 
   $url = strstr($request_uri,'?') ? $request_uri :  $request_uri.'?';
   
   if(is_array($query))
    $url .= http_build_query($query);
   else if($query != "")
    $url .= "&".trim($query, "?&");
  
   $arr = parse_url($url);

   if(isset($arr["query"])){
    parse_str($arr["query"], $arrs);
    unset($arrs["page"]);
    $url = $arr["path"].'?'.http_build_query($arrs);
   }
   
   if(strstr($url, '?')) {
    if(substr($url, -1)!='?')
     $url = $url.'&';
   }else{
    $url = $url.'?';
   }
   
   return $url;
  }

  /* 在對象內部使用的私有方法,用於獲取當前頁開始的記錄數 */
  private function start(){
   if($this->total == 0)
    return 0;
   else
    return ($this->page-1) * $this->listRows+1;
  }

  /* 在對象內部使用的私有方法,用於獲取當前頁結束的記錄數 */
  private function end(){
   return min($this->page * $this->listRows, $this->total);
  }

  /* 在對象內部使用的私有方法,用於獲取上一頁和首頁的操作信息 */
  private function firstprev(){
   if($this->page > 1) {
    $str = " <a href='{$this->uri}page=1'>{$this->config["first"]}</a> ";
    $str .= "<a href='{$this->uri}page=".($this->page-1)."'>{$this->config["prev"]}</a> ";  
    return $str;
   }

  }
 
  /* 在對象內部使用的私有方法,用於獲取頁數列表信息 */
  private function pageList(){
   $linkPage = " <b>";
   
   $inum = floor($this->listNum/2);
   /*當前頁前面的列表 */
   for($i = $inum; $i >= 1; $i--){
    $page = $this->page-$i;

    if($page >= 1)
     $linkPage .= "<a href='{$this->uri}page={$page}'>{$page}</a> ";
   }
   /*當前頁的信息 */
   if($this->pageNum > 1)
    $linkPage .= "<span style='padding:1px 2px;background:#BBB;color:white'>{$this->page}</span> ";
   
   /*當前頁後面的列表 */
   for($i=1; $i <= $inum; $i++){
    $page = $this->page+$i;
    if($page <= $this->pageNum)
     $linkPage .= "<a href='{$this->uri}page={$page}'>{$page}</a> ";
    else
     break;
   }
   $linkPage .= '</b>';
   return $linkPage;
  }

  /* 在對象內部使用的私有方法,獲取下一頁和尾頁的操作信息 */
  private function nextlast(){
   if($this->page != $this->pageNum) {
    $str = " <a href='{$this->uri}page=".($this->page+1)."'>{$this->config["next"]}</a> ";
    $str .= " <a href='{$this->uri}page=".($this->pageNum)."'>{$this->config["last"]}</a> ";
    return $str;
   }
  }

  /* 在對象內部使用的私有方法,用於顯示和處理表單跳轉頁面 */
  private function goPage(){
       if($this->pageNum > 1) {
    return ' <input style="width:20px;height:17px !important;height:18px;border:1px solid #CCCCCC;" type="text" onkeydown="javascript:if(event.keyCode==13){var page=(this.value>'.$this->pageNum.')?'.$this->pageNum.':this.value;location=\''.$this->uri.'page=\'+page+\'\'}" value="'.$this->page.'"><input style="cursor:pointer;width:25px;height:18px;border:1px solid #CCCCCC;" type="button" value="GO" onclick="javascript:var page=(this.previousSibling.value>'.$this->pageNum.')?'.$this->pageNum.':this.previousSibling.value;location=\''.$this->uri.'page=\'+page+\'\'"> ';
   }
  }

  /* 在對象內部使用的私有方法,用於獲取本頁顯示的記錄條數 */
  private function disnum(){
   if($this->total > 0){
    return $this->end()-$this->start()+1;
   }else{
    return 0;
   }
  }
 }

 
 
 


 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved