php mysql テンプレート ページングの例 class_PHP チュートリアル

WBOY
リリース: 2016-07-13 16:54:45
オリジナル
958 人が閲覧しました

/*
* 模板分页类,源于easp教程的数据库教程分页方法,算是easp分页的的php独立版
* 支持动态和静态分页方式
* easp官网http://easp.lengshi.com/
* 作者:钟晶晶
* 日期:2010-11-3
* 邮箱:zhongjingjing@gmail.com
* 博客:http://blog.zaimer.com
* page([总记录数=1],[分页大小=20],[当前页=1],[显示页数=6],[分页参数='page'],[分页链接=当前页面],[是否静态=false])
* 动态:
* 简单用法:
* $page = new page(50);
* $page->setpager('zjj','
共有{recordcount} 个商品 当前第 {pageindex} 页 / 共 {pagecount} 页 分页: {first}{prev} {list} {next}{last} 转到 {jump} 页
',array("listlong"=>"6","first"=>"首页","last"=>"尾页","prev"=>"上一页","next"=>"下一页","list"=>"第*页","jump"=>"select"));
 * echo $page->getpager('zjj');
 * 全参数用法:
 * $page = new page(50,20,1,6,'page','prrr.php',false);
 * $page->setpager('zjj','
共有{recordcount} 个商品 当前第 {pageindex} 页 / 共 {pagecount} 页 分页: {first}{prev} {list} {next}{last} 转到 {jump} 页
',array("listlong"=>"6","first"=>"首页","last"=>"尾页","prev"=>"上一页","next"=>"下一页","list"=>"第*页","jump"=>"select"));
 * echo $page->getpager('zjj');
 * 静态:
 * $page = new page(50,20,1,6,'page','prrr{page}.html',true);
 * $page->setpager('zjj','
共有{recordcount} 个商品 当前第 {pageindex} 页 / 共 {pagecount} 页 分页: {first}{prev} {list} {next}{last} 转到 {jump} 页
',array("listlong"=>"6","first"=>"首页","last"=>"尾页","prev"=>"上一页","next"=>"下一页","list"=>"第*页","jump"=>"select"));
 * echo $page->getpager('zjj');
 */
class page {
 private $page_size; //每页显示的条目数
 private $total_size; //总条目数
 private $current_page; //当前被选中的页
 private $sub_pages; //每次显示的页数
 private $total_pages; //总页数
 private $page_tpl = array (); // 分页模板
 private $pageparam;
 private $pagelink;
 private $static;
 
 function __construct($total_size = 1, $page_size = 20, $current_page = 1, $sub_pages = 6, $pageparam = 'page', $pagelink = '', $static = false) {
  $this->page_size = intval ( $page_size );
  $this->total_size = intval ( $total_size );
  if (! $current_page) {
   $this->current_page = 1;
  } else {
   $this->current_page = intval ( $current_page );
  }
  $this->total_pages = ceil ( $total_size / $page_size );
  $this->sub_pages = intval ( $sub_pages );
  $this->pageparam = $pageparam;
  $this->pagelink = (empty ( $pagelink ) ? $_server ["php_self"] : $pagelink);
  $this->static = $static;
  $this->page_tpl ['default'] = array ('tpl' => '
{first}{prev}{liststart}{list}{listend}{next}{last} 跳转到{jump}页
', 'config' => 配列 () );

}
パブリック関数 __set($param, $value) {
$this->$param = $value;
}
パブリック関数 __get($param) {
$this->$param;
を返す }
/*
__destruct デストラクターは、クラスが使用されなくなったときに呼び出され、リソースを解放するために使用されます。
*/
関数 __destruct() {
unset ($page_size); //各ページに表示されるアイテムの数
unset ($total_size); // エントリの総数
unset ($current_page); //現在選択されているページ
unset ( $sub_pages ); // 毎回表示されるページ数
unset ( $total_pages ) // 総ページ数
unset ( $page_tpl ); // ページング テンプレート
unset ($pageparam); // ページングパラメータ、デフォルトページ
設定を解除 ( $pagelink );
設定を解除 ( $static );
}
プライベート関数 urlparameters($url = array()) {
foreach ( $url as $key => $val ) {
if ($key != $this->pageparam)
$arg [] = $key . $val;
}
$arg [] = $this->pageparam '=*';
if ($this->static)
Return str_replace ( '{page}', '*', $this->pagelink );
それ以外
$this->pagelink を返します。 }
public function setpager($tpl_name = 'default', $tpl = '', $config = array()) {
if (空 ( $tpl ))
$tpl = $this->page_tpl ['default'] ['tpl'];
if (空 ( $config ))
$config = $this->page_tpl ['default'] ['config'];
$this->page_tpl [$tpl_name] = array ('tpl' => $tpl, 'config' => $config );
}
パブリック関数 getpager($tpl_name = 'default') {
$this->getcurrentpage();
Return $this->pager ( $this->page_tpl [$tpl_name] );
}
パブリック関数 getcurrentpage() {
$this->current_page = ($_get [$this->pageparam] <= intval ( $this->total_pages ) ? ($_get [$this->pageparam] < 1 ? 1 : $_get [$this->pageparam]) : intval ( $this->total_pages ));
}
パブリック関数ページャー($page_tpl = '') {
if (空 ( $page_tpl ))
$page_tpl = $this->page_tpl ['デフォルト'];
$cfg = array ('recordcount' => intval ( $this->total_size ), 'pageindex' => intval ( $this->current_page ), 'pagecount' => intval ( $this-> total_pages )、'pagesize' => intval ( $this->page_size )、'listlong' => intval ( $this->sub_pages )、'listsidelong' => *'、'currentclass' => 'current'、'link' => $this->urlparameters ( $_get )、'first' => ' 8249;'、'次' => '›'、'最後' => '...'、'無効クラス' => 'ジャンプ' => '入力'、'ジャンププラス' => 'ジャンプアクション' => );
if (! empty ( $page_tpl ['config'] )) {
foreach ( $page_tpl ['config'] as $key => $val ) {
If (array_key_exists ( $key, $cfg ))
$cfg [$key] = $val;
}
}
$tmps チュートリアル tr = $page_tpl ['tpl'];
$pstart = $cfg ['pageindex'] - (($cfg ['listlong'] / 2) + ($cfg ['listlong'] % 2)) + 1;
$pend = $cfg ['pageindex'] + $cfg ['listlong'] / 2;
if ($pstart $pstart = 1;
$pend = $cfg ['listlong'];
}
if ($pend > $cfg ['pagecount']) {
$pstart = $cfg ['pagecount'] - $cfg ['listlong'] + 1;
$pend = $cfg ['ページ数'];
}
if ($pstart $pstart = 1;
for($i = $pstart; $i if ($i == $cfg ['pageindex'])
$plist .= '' . str_replace ( '*', $i, $cfg ['list'] ) . ;';
それ以外
$plist .= ' ' . str_replace ( '*', $i, $cfg ['リスト'] ) ' }
  if ($cfg ['listsidelong'] > 0) {
   if ($cfg ['listsidelong'] < $pstart) {
    for($i = 1; $i      $pliststart .= '' 。 str_replace ( '*', $i, $cfg ['list'] ) 。 ' ';
    }
    $pliststart .= ($cfg ['listsidelong'] + 1) == $pstart ? '' : $cfg ['詳細'] 。 ' ';
   } その他 {
    if ($cfg ['listsidelong'] >= $pstart && $pstart > 1) {
     for($i = 1; $i       $pliststart .= '' 。 str_replace ( '*', $i, $cfg ['list'] ) 。 ' ';
     }
    }
   }
   if (($cfg ['pagecount'] - $cfg ['listsidelong']) > $pend) {
    $plistend = ' ' 。 $cfg ['詳細'] 。 $plistend;
    for($i = (($cfg ['pagecount'] - $cfg ['listsidelong']) + 1); $i      $plistend .= ' ' 。 str_replace ( '*', $i, $cfg ['list'] ) 。 ' ';
    }
   } その他 {
    if (($cfg ['pagecount'] - $cfg ['listsidelong']) <= $pend && $pend < $cfg ['pagecount']) {
     for($i = ($pend + 1); $i       $plistend .= ' ' 。 str_replace ( '*', $i, $cfg ['list'] ) 。 ' ';
     }
    }
   }
  }
  if ($cfg ['pageindex'] > 1) {
   $pfirst = ' ' 。 $cfg ['最初'] 。 ' ';
   $pprev = ' ' 。 $cfg ['前'] 。 ' ';
  } その他 {
   $pfirst = ' ' 。 $cfg ['前'] 。 ' ';
  }
  if ($cfg ['pageindex'] < $cfg ['pagecount']) {
   $plast = ' ' 。 $cfg ['最後'] 。 ' ';
   $pnext = ' ' 。 $cfg ['次'] 。 ' ';
  } その他 {
   $plast = ' ' 。 $cfg ['次'] 。 ' ';
  }
  switch (strto lower ( $cfg ['jump'] )) {
   ケース「入力」:
    $pjumpvalue = 'this.value';
    $pjump = '     $pjump .= ' onkeydown="网页特效:if(event.charcode==13||event.keycode==13){if(!isnan(' . $pjumpvalue . ')){';
    $pjump .= ($cfg ['jumpaction'] == '' ? ((strto lower ( substr ( $cfg ['link'], 0, 11 ) ) == 'javascript:') ? str_replace ( '*', $pjumpvalue, substr ( $cfg ['link'], 12 ) ) : " document.location.href='" . str_replace ( '*', ''+' . $pjumpvalue . '+'', $cfg [' link'] ) . '';') : str_replace ( "*", $pjumpvalue, $cfg ['jumpaction'] ));
    $pjump .= '}return false;}" />';
    休憩;
   ケース「選択」:
    $pjumpvalue = "this.options[this.selectedindex].value";
    $pjump = '     $pjump .= '" title="请选择要跳转到的页数"> ';
    if ($cfg ['jumplong'] == 0) {
     for($i = 0; $i       $pjump .= '<オプション値="' . $i . '"' . (($i == $cfg ['pageindex']) ? ' selected="選択済み"' : '') 。 「>」 。 $i 。 ' ';
     }
    } その他 {
     $pjumplong = intval ( $cfg ['jumplong'] / 2 );
     $pjumpstart = ((($cfg ['pageindex'] - $pjumplong)      $pjumpstart = ((($cfg ['pagecount'] - $cfg ['pageindex']) < $pjumplong) ? ($pjumpstart - ($pjumplong - ($cfg ['pagecount'] - $cfg ['pageindex') '])) + 1) : $pjumpstart);
     $pjumpstart = (($pjumpstart      $j = 1;
     for($i = $pjumpstart; $i       $pjump .= '<オプション値="' . $i . '"' . (($i == $cfg ['pageindex']) ? ' selected="選択済み"' : '') 。 「>」 。 $i 。 ' ';
     }
     $pjumplong = $cfg ['pagecount'] - $cfg ['pageindex'] < $pjumplong ? $pjumplong : $pjumplong + ($pjumplong - $j) + 1;
     $pjumpend = $cfg ['pageindex'] + $pjumplong > $cfg ['ページ数'] ? $cfg ['pagecount'] : $cfg ['pageindex'] + $pjumplong;
     for($i = $cfg ['pageindex'] + 1; $i <= $pjumpend; $i ++) {
      $pjump .= '<オプション値="' . $i . ''>' 。 $i 。 ' ';
     }
    }
    $pjump .= '';
    休憩;
  }
  $patterns = array ('/{recordcount}/', '/{pagecount}/', '/{pageindex}/', '/{pagesize}/', '/{list}/', '/{liststart} /'、'/{listend}/'、'/{first}/'、'/{prev}/'、'/{next}/'、'/{last}/'、'/{jump}/' );
  $replace = array ($cfg ['recordcount'], $cfg ['pagecount'], $cfg ['pageindex'], $cfg ['pagesize'], $plist, $pliststart, $plistend, $pfirst, $ pprev、$pnext、$plast、$pjump );
  $tmpstr = chr(13) 。 chr(10) 。 preg_replace ( $patterns, $replace, $tmpstr ) 。 chr(13) 。 chr ( 10 );
  設定を解除 ( $cfg );
  $tmpstr;
を返します  }
}
?>

www.bkjia.comtru​​ehttp://www.bkjia.com/PHPjc/631735.html技術記事 ?php教程 /* * 模板分页类、easp教程のデータベース库教程分页方法、計算はeasp分页的のphp独立版 * サポートアニメーション态および静态分页方式 * easp官网http://easp.leng...
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!