php中自定义分页处理类
来源:互联网 发布:卷皮网淘宝客源码 编辑:程序博客网 时间:2024/06/01 08:42
<?php
/**
* @(#)pages.php
* PHP version 5.2.3
*
*
* Copyright 2007 SoftRoad. All Rights Reserved.
*
*====================================================================
* 変更履歴
*
* 新規作成 2007 年5月17日 蒋彪
*/
//require ("../common/dbutil.php");
//require ("../common/config.php");
class PageBean {
/*
* 総ページ数
*/
var $totalPageNumber = 0;
/*
* 当面のページ
*/
var $currentPageNumber = 1;
/*
* 最大レコードの件数
*/
var $pageSize;
/*
* 検索結果
*/
var $result;
/*
* 検索sql
*/
var $sql;
/*
* データベースの処理対象
*/
var $dbutil;
/*
* 総コードの件数
*/
var $totalItem = 0;
/*
* 構造関数
*/
function __construct($sql, $currentPageNumber, $pageSize) {
$this->dbutil = new DBUtil();
$this->sql = $sql;
$this->currentPageNumber = $currentPageNumber;
$this->pageSize = $pageSize;
}
/*
* 総ページ数を設定する
*/
function setTotalPageNumber() {
$this->totalPageNumber = ceil($this->getTotalItem() / $this->pageSize);
}
/*
* 総コードの件数を設定する
*/
function setTotalItem() {
$this->dbutil->connectDb(dbtype, connectType, dbconnect, dbusr, dbpwd);
$result = $this->dbutil->executeQuery($this->sql);
$rowNum = $this->dbutil->rowsNumber($result);
$this->totalItem = $rowNum;
$this->dbutil->closeDb();
}
/*
* 総コードの件数を取得する
*/
function getTotalItem() {
return $this->totalItem;
}
/*
* 総ページ数を取得する
*/
function getTotalPageNumber() {
return $this->totalPageNumber;
}
/*
* 当面のページを設定する
*/
function setCurrentPageNumber($currentPageNumber) {
$this->currentPageNumber = $currentPageNumber;
}
/*
* 当面のページをを取得する
*/
function getCurrentPageNumber() {
return $this->currentPageNumber;
}
/*
* ページ内表示リスト件数を設定する
*/
function setPageSize($pageSize) {
$this->pageSize = $pageSize;
}
/*
* ページ内表示リスト件数
*/
function getPageSize() {
return $this->pageSize;
}
/*
* 最後のページチェック
*/
function isHasNextPage() {
$temp = $this->getCurrentPageNumber() + 1;
if ($temp > $this->getTotalPageNumber()) {
return false;
} else {
return true;
}
}
/*
* 最前のページチェック
*/
function isHasPreviousPage() {
$temp = $this->getCurrentPageNumber() - 1;
if ($temp < 1) {
return false;
} else {
return true;
}
}
/*
* ページ内表示のデータを取得する
*/
function getPageList() {
$this->setTotalItem();
$this->setTotalPageNumber();
$sql = $this->sql . " limit " . $this->getPageSize() . " offset " . ($this->currentPageNumber - 1) * $this->getPageSize();
$this->dbutil->connectDb(dbtype, connectType, dbconnect, dbusr, dbpwd);
$this->result = $this->dbutil->select($sql);
$this->dbutil->closeDb();
return $this->result;
}
/*
* 改頁を取得
*/
function getToolBar() {
$from=($this->getCurrentPageNumber() - 1) * $this->getPageSize() + 1;
$to=$this->getCurrentPageNumber() * $this->getPageSize();
if((int)$to > (int)$this->getTotalItem()){
$to=$this->getTotalItem();
}
if (!$this->isHasNextPage() && !$this->isHasPreviousPage()) {//only one page
$firstNav='最初 ';
$strPreviousNav = '前へ ';
$strPageNum = $this->getCurrentPageNumber();
$strNextNav = ' 次へ';
$strInfo = '最後 (' . $this->getTotalItem() . "件ヒット 1 - ". $this->getPageSize()." 件表示)";
} else if ($this->isHasNextPage() && $this->isHasPreviousPage()) {
$firstNav="<a href=/"javascript:goTo(1);/">最初</a>";
$strPreviousNav = " <a href=/"javascript:goTo(" . ($this->getCurrentPageNumber() - 1) . ");/">前へ</a> ";
$strPageNum = $this->getCurrentPageNumber();
$strNextNav = " <a href=/"javascript:goTo(" . ($this->getCurrentPageNumber() + 1) . ");/">次へ</a>";
$strInfo = " <a href=/"javascript:goTo(" . $this->getTotalPageNumber(). ");/">最後</a>".'(' . $this->getTotalItem() . "件ヒット " .$from . " - " . $to . "件表示)";
} else if ($this->isHasNextPage() && !$this->isHasPreviousPage()) {//no Previous Page
$firstNav='最初 ';
$strPreviousNav = "前へ ";
$strPageNum = $this->getCurrentPageNumber();
$strNextNav = " <a href=/"javascript:goTo(" . ($this->getCurrentPageNumber() + 1) . ");/"> 次へ</a>";
$strInfo = " <a href=/"javascript:goTo(" . $this->getTotalPageNumber() . ");/">最後</a>".'(' . $this->getTotalItem() . "件ヒット " .$from . " - " . $to . "件表示)";
} else if (!$this->isHasNextPage() && $this->isHasPreviousPage()) {//no Next Page
$firstNav="<a href=/"javascript:goTo(1);/">最初</a>";
$strPreviousNav = " <a href=/"javascript:goTo(" . ($this->getCurrentPageNumber() - 1) . ");/">前へ </a> ";
$strPageNum = $this->getCurrentPageNumber();
$strNextNav = " 次へ ";
$strInfo = "最後".'(' . $this->getTotalItem() . "件ヒット " .$from . " - " . $to . "件表示)";
}
return $firstNav.$strPreviousNav . $strPageNum . $strNextNav . $strInfo;
}
}
?>
- php中自定义分页处理类
- php中自定义分页处理类
- php中自定义数据库处理类
- PHP中模板分页的处理
- PHP中模板分页的处理
- PHP中模板分页的处理
- PHP中模板分页的处理
- PHP中模板分页的处理
- ORACLE自定义分页处理
- 自定义PHP分页函数
- 自定义PHP分页函数
- php自定义分页
- PHP中用户自定义Session处理机制
- PHP封装的分页导航处理类
- PHP中对数组进行分页处理的原理及分页实例
- 自定义PHP系统异常处理类
- PHP自定义异常处理
- php session自定义处理
- 关于vs2005中用户控件的路径和超级链接
- 一分钟搞定url重写!
- Windows CE下的蓝牙开发
- 在Ubuntu中启用root帐户
- oracle.jdbc.driver.OracleDriver和oracle.jdbc.OracleDriver这两个驱动有什么区别?
- php中自定义分页处理类
- 停水三天――准备
- 摔倒了又怎样..爬起来不就行了..
- 每个.Net开发人员应该下载的十种必备工具
- 在build zone中编译OpenSolaris
- php中自定义日志处理类(类似于java中的log4j)
- 实现业务系统中的用户权限管理--设计篇
- 友遇洪峰
- php中自定义数据库处理类