• PHP分页类


    View Code
      1 <?php
      2 /**
      3  * datagrid by asmfang Q184377367
      4  *
      5  */
      6 class datagrid{
      7     
      8     //每页显示数量
      9     public  $evetotal        = 0;
     10     //数据总数
     11     public  $datacount        = 0;
     12     //总页数
     13     public  $pagetotal         = 0;
     14     //当前页码
     15     public  $currentpage    = 0;
     16     
     17     /**
     18         array = (url,target);
     19      */
     20     public  $urlroute     = array();
     21     
     22     //数据结果集
     23     public $res = array();
     24     
     25 
     26     /**
     27      * 初始化动作,通过外部回调函数获取数据
     28      *
     29      * @param object $dbobj          数据对象
     30      * @param string $callback        数据对象回调方法
     31      * @param string $datastr        SQL连接字符
     32      * @param int $datacount        数据总数
     33      * @param int $_evetotal        每页显示数量
     34      * @param string $url            URL连接
     35      */
     36     public function init_data(     $dbobj,
     37                                 $callback, 
     38                                 $datastr, 
     39                                 $datacount, 
     40                                 $_evetotal
     41                                 ) {
     42         
     43         $this->evetotal     = $_evetotal;                                     //每页显示
     44         $this->datacount     = $datacount;                                     //数据总数
     45         $this->pagetotal    = ceil( $this->datacount / $this->evetotal );     //总页数
     46         $this->currentpage     =  ( $this->currentpage <= 0x00000000 )         ? 1 : $this->currentpage ;
     47         $this->currentpage     =  ( $this->currentpage > $this->pagetotal )     ? $this->pagetotal : $this->currentpage;
     48         $offset                =  ($this->currentpage - 1) * $this->evetotal;
     49         $datastr            .=  ' LIMIT '. $offset .','.$this->evetotal;
     50         $this->res           =  $dbobj->$callback( $datastr );
     51 
     52     }
     53     
     54     public function init_page_parem( $url = '', $tag = 'self', $sufix = 'p', $cpage = 0, $gpage = true ){
     55         $this->urlroute['gpage']     = $gpage;
     56         $this->urlroute['url']         = $url;
     57         $this->urlroute['tag']         = $tag;
     58         $this->urlroute['sufix']     = $sufix;
     59         $this->urlroute['cpage']     = $cpage;
     60         if ( $this->urlroute['gpage'] ) {
     61              $this->currentpage     =  isset( $_GET[$this->urlroute['sufix']] ) ? (int)( $_GET[$this->urlroute['sufix']] ) : 1;
     62              
     63         } else {
     64             $this->currentpage = $this->urlroute['cpage'];
     65         }
     66         
     67     }
     68     
     69     public function show(){
     70         
     71         $this->show_datagrid();
     72         $mpurl = strpos( $this->urlroute['url'], '?' ) ? '&' : '?';
     73         $html  = '<table><tr>';
     74         for ( $i=1; $i <= $this->pagetotal; $i++ ) {
     75             $html.= '<td><a href=' .$this->urlroute['url'].$mpurl. 
     76                                     $this->urlroute['sufix'].'='.$i.' target='. 
     77                                     $this->urlroute['tag'] .'>[ ' .$i. ' ]</a></td>';
     78         }
     79         $html.= '</tr></table>';
     80         echo $html;
     81         unset( $mpurl,$html );
     82     }
     83     
     84 
     85     private function show_datagrid() {
     86         $html = '<table style=\'border: solid 1px #000000;900px;border-collapse: collapse;\'>';
     87         foreach ( $this->res as $key => $val) {
     88             
     89             $html .= '<tr>';
     90             foreach ( $val as $keya => $vala ) {
     91                 
     92                 $html .= '<td style=\'border:1px #000000 solid;\'>';
     93                 $html .=  $vala;
     94                 $html .= '</td>';
     95                 
     96             }
     97             $html .= '</tr>';
     98             
     99         }
    100         $html .= '</table>';
    101         echo $html;
    102     }
    103     
    104 
    105     
    106 }
    107 
    108 
    109 ?>
    java新手自学群 626070845
    java/springboot/hadoop/JVM 群 4915800
    Hadoop/mongodb(搭建/开发/运维)Q群481975850
    GOLang Q1群:6848027
    GOLang Q2群:450509103
    GOLang Q3群:436173132
    GOLang Q4群:141984758
    GOLang Q5群:215535604
    C/C++/QT群 1414577
    单片机嵌入式/电子电路入门群群 306312845
    MUD/LIB/交流群 391486684
    Electron/koa/Nodejs/express 214737701
    大前端群vue/js/ts 165150391
    操作系统研发群:15375777
    汇编/辅助/破解新手群:755783453
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    Linux异步IO
    基本数据类型总结--
    总结
    字典魔法二
    字典及其魔法
    元祖的魔法
    列表的特点
    运算符
    while ……else……和while……continue……和 while…………break…………
    作业---写一个程序,用户名 、密码输入错误3次 错误
  • 原文地址:https://www.cnblogs.com/cfas/p/2491577.html
Copyright © 2020-2023  润新知