http://www.phpx.com/happy/thr53150.html
解决方案 »
- 新手php时间比较问题 ~~求解!
- 统计网站访问量
- 大家给我推荐一款好用的php IDE
- PHP入门
- 【求助】php对资源限时锁定的实现方式
- PHP写入MYSQL数据库出现乱码的问题
- MySQL 错误 Warning: Supplied argument is not a valid MySQL result resource in
- 一个很菜的问题,呵呵
- zend开办的 PHP 5 Coding Contest 落下帷幕了, 大家去凑热闹去啊, 优秀的代码 / 架构 一箩筐.........
- 一个switch的问题
- linux下有好用的PHP编译器吗?
- 请问,现在做网站大都有后台的吗?是不是用后台来管理网站比较容易?没用过!
/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
+------------------------------------------------------------+
| Filename.......: pagenav.php |
| Project........: 大白菜芯 |
| Version........: 2.0.0 |
| Last Modified..: 2003-01-16 |
+------------------------------------------------------------+
| Author(MSN).........: tyler.wu <[email protected]> |
| Homepage.......: http://tjsohu.com |
| Support........: http://tjsohu.com |
+------------------------------------------------------------+
| Copyright (C) 2004 tjsohu.com Team. All rights reserved. |
+------------------------------------------------------------+
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
error_reporting(7);class buildNav{ var $limit;
var $execute,$query;
var $total_result = 0;
var $offset = "offset";
function buildNav($Public,$objClass)
{
$this->Public=$Public;
$this->theClass = "class=".$objClass ;
} function execute($query,$limit){// global $product;
$GLOBALS[$this->offset] = (!isset($GLOBALS[$this->offset]) OR $GLOBALS[$this->offset]<0) ? 0 : $GLOBALS[$this->offset];
//$this->sql_result = $DB->query($query); $GLOBALS[$this->offset] = ($GLOBALS[$this->offset]>$this->total_result) ? $this->total_result-10 : $GLOBALS[$this->offset];// if (empty($this->limit)) {
if (empty($limit) || $limit=="") {
$this->limit = 20;
}else{
$this->limit = $limit;
} if (isset($this->limit)) {
$query .= " LIMIT " . $GLOBALS[$this->offset] . ", $this->limit";
$this->sql_result = $this->Public->query($query);
$this->num_pages = ceil($this->total_result/$this->limit);
}
if ($GLOBALS[$this->offset]+1 > $this->total_result) {
$GLOBALS[$this->offset] = $this->total_result-1;
} }
function show_num_pages($frew = "«", $rew = '上一页', $ffwd = '»', $fwd = '下一页', $separator = '') {
$current_pg = $GLOBALS[$this->offset]/$this->limit+1;
if ($current_pg > '5') {
$fgp = ($current_pg-5 > 0) ? $current_pg-5 : 1;
$egp = $current_pg+4;
if ($egp > $this->num_pages) {
$egp = $this->num_pages;
$fgp = ($this->num_pages-9 > 0) ? $this->num_pages-9 : 1;
}
} else {
$fgp = 1;
$egp = ($this->num_pages >= 10) ? 10 : $this->num_pages;
}
if($this->num_pages > 1) {
// searching for http_get_vars
foreach ($GLOBALS[HTTP_GET_VARS] as $_get_name => $_get_value) {
if ($_get_name != $this->offset) {
$this->_get_vars .= "&$_get_name=$_get_value";
}
}
$this->listNext = $GLOBALS[$this->offset] + $this->limit;
$this->listPrev = $GLOBALS[$this->offset] - $this->limit;
// $this->theClass = $objClass;
if (!empty($rew)) { //$separator [$frew] $rew
$return .= ($GLOBALS[$this->offset] > 0) ? "<a href=\"$GLOBALS[PHP_SELF]?$this->offset=0$this->_get_vars\" $this->theClass title=\"第一页\">$frew</a> <a href=\"$GLOBALS[PHP_SELF]?$this->offset=$this->listPrev$this->_get_vars\" $this->theClass title=\"上一页\">$rew</a> $separator " : "";
} // showing pages
if ($this->show_pages_number || !isset($this->show_pages_number)) {
for($this->a = $fgp; $this->a <= $egp; $this->a++) {
$this->theNext = ($this->a-1)*$this->limit;
if ($this->theNext != $GLOBALS[$this->offset]) {
$return .= " <a href=\"$GLOBALS[PHP_SELF]?$this->offset=$this->theNext$this->_get_vars\" $this->theClass> ";
if ($this->number_type == 'alpha') {
$return .= chr(64 + ($this->a));
} else {
$return .= $this->a;
}
$return .= "</a> ";
} else {
if ($this->number_type == 'alpha') {
$return .= chr(64 + ($this->a));
} else {
$return .= "<b>$this->a</b>";
}
$return .= ($this->a < $this->num_pages) ? " $separator " : "";
}
}
$this->theNext = $GLOBALS[$this->offset] + $this->limit;
if (!empty($fwd)) {
$offset_end = ($this->num_pages-1)*$this->limit; //$separator $fwd [$ffwd]
$return .= ($GLOBALS[$this->offset] + $this->limit < $this->total_result) ? "$separator <a href=\"$GLOBALS[PHP_SELF]?$this->offset=$this->listNext$this->_get_vars\" $this->theClass title=\"下一页\">$fwd</a> <a href=\"$GLOBALS[PHP_SELF]?$this->offset=$offset_end$this->_get_vars\" $this->theClass title=\"最后一页\">$ffwd</a>" : "";
}
}
}
return $return;
} // [Function : Showing the Information for the Offset]
function show_info() { $return .= "共: ".$this->total_result." , ";
$list_from = ($GLOBALS[$this->offset]+1 > $this->total_result) ? $this->total_result : $GLOBALS[$this->offset]+1;
$list_to = ($GLOBALS[$this->offset]+$this->limit >= $this->total_result) ? $this->total_result : $GLOBALS[$this->offset]+$this->limit;
//$return .= 'Showing Results from ' . $list_from . ' - ' . $list_to . '<br>';
$return .= "显示: ".$list_from ." - ".$list_to;
return $return;
} function pagenav() { // global $objClass;
// $this->theClass = $objClass ;
$return = "
<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"4\">
<tr>
<td ".$this->theClass.">".$this->show_info()."</td>
<td align=\"right\" ".$this->theClass.">".$this->show_num_pages()."</td>
</tr>
</table>"; return $return;
}
}
?>
http://blog.csdn.net/kingerq/archive/2004/09/29/120354.aspx
<?php
//
// +--------------------------------------------------------------------+
// | My ADODB pager.inc.php |
// +--------------------------------------------------------------------+
// | Copyright (c) 2005 Confu.Net All rights reserved |
// +--------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | [email protected] so we can mail you a copy immediately. |
// +--------------------------------------------------------------------+
// | Author: confu <[email protected]> |
// +--------------------------------------------------------------------+
//
// ** MUST be run with ADODB, a fit class for SMARTY **
class Pager {
var $sql; // SQL语句
var $DB; // DB实例
var $currLink; // 当前链接
var $currPage; // 当前页码
var $id; // 当前链接
var $showPageLinks;
var $rows; // 每页记录数
var $cache = 0; // secs to cache with CachePageExecute()
var $rs; // recordset generated // 设置本地化分页信息提示
var $page = '页:'; // 页码
var $record = '记录:'; // 记录
var $first = '<FONT face="Webdings">9</FONT>';
var $prev = '<FONT face="Webdings">3</FONT>';
var $next = '<FONT face="Webdings">4</FONT>';
var $last = '<FONT face="Webdings">:</FONT>';
var $moreLinks = '<FONT face="Webdings">8</FONT>';
var $startLinks = '<FONT face="Webdings">7</FONT>';
var $linkSelectedColor = 'red'; /**
* 构造函数
*
* @param object ADODB实例
* @param string SQL语句
* @param string 页码传值变量名,默认:page
*
* @return none
* @access public
*/
function Pager($DB, $sql, $id='page', $showPageLinks = false)
{
$this->sql = $sql;
$this->DB = $DB;
$this->id = $id;
$this->currPage = !isset($_GET[$this->id]) ? 1 : $_GET[$this->id]; //取得当前页码
//取得当前URL链接
if(!isset($_GET[$this->id])){
$this->currLink = $_SERVER['QUERY_STRING']=='' ? $_SERVER['REQUEST_URI'].'?' : $_SERVER['REQUEST_URI'].'&';
}else{
$this->currLink = str_replace($this->id."=".$this->currPage, "", $_SERVER['REQUEST_URI']);
} $this->showPageLinks = $showPageLinks;
} /**
* 返回当前查询记录值数组
*
* @param int 返回记录数,即每页显示记录数
*
* @return array
* @access public
*/
function listData($rows = 10)
{
global $ADODB_COUNTRECS;
$this->rows = $rows;
if ($this->DB->dataProvider == 'informix') $this->DB->cursorType = IFX_SCROLL;
$savec = $ADODB_COUNTRECS;
if ($this->DB->pageExecuteCountRows) $ADODB_COUNTRECS = true;
if ($this->cache)
$rs = &$this->DB->CachePageExecute($this->cache,$this->sql,$rows,$this->currPage);
else
$rs = &$this->DB->PageExecute($this->sql,$rows,$this->currPage);
$ADODB_COUNTRECS = $savec;
$this->rs = &$rs;
if (!$rs) {
print "<h3>Query failed: $this->sql</h3>";
return;
}
$arrayData = array();
while($data = $rs->FetchRow()){
array_push($arrayData,$data);
}
return $arrayData;
} /**
* 返回当前查询记录及页码信息
*
* @param none
*
* @return string
* @access public
*/
function getRecordPageCount()
{
if (!$this->DB->pageExecuteCountRows) return '';
$lastPage = $this->rs->LastPageNo();
if ($lastPage == -1) $lastPage = 1; // check for empty rs.
if ($this->currPage > $lastPage) $this->currPage = 1;
//记录信息
if($this->rs->NumRows()!=0){
$recordInfo = ($this->currPage-1)*$this->rows.'-'.(($this->currPage-1)*$this->rows+$this->rs->NumRows());
}else{
$recordInfo = 0;
}
return $this->record.$recordInfo.' '.$this->page.$this->currPage.'/'.$lastPage;
} /**
* 返回当前分页信息导航
*
* @param none
*
* @return string
* @access public
*/
function getPageNumNav()
{
$pageNumNav = '';
if (!$this->rs->AtFirstPage()) {
$pageNumNav.= $this->_renderFirst();
$pageNumNav.= $this->_renderPrev();
} else {
$pageNumNav.= $this->_renderFirst(false);
$pageNumNav.= $this->_renderPrev(false);
}
if ($this->showPageLinks){
$pageNumNav.= $this->_renderPageLinks();
}
if (!$this->rs->AtLastPage()) {
$pageNumNav.= $this->_renderNext();
$pageNumNav.= $this->_renderLast();
} else {
$pageNumNav.= $this->_renderNext(false);
$pageNumNav.= $this->_renderLast(false);
}
return $pageNumNav;
} /**
* 首页链接
*
* @param Boolean
*
* @return string
* @access private
*/
function _renderFirst($anchor=true){
if ($anchor) {
$s = '<a href="'.$this->currLink.$this->id.'=1">'.$this->first.'</a> ';
} else {
$s = "$this->first ";
}
return $s;
} /**
* 上一页链接
*
* @param Boolean
*
* @return string
* @access private
*/
function _renderPrev($anchor=true){
if ($anchor) {
$s = '<a href="'.$this->currLink.$this->id.'='.($this->rs->AbsolutePage()-1).'">'.$this->prev.'</a> ';
} else {
$s = "$this->prev ";
}
return $s;
} /**
* 分页数值链接
*
* @param none
*
* @return string
* @access private
*/
function _renderPageLinks()
{
$pages = $this->rs->LastPageNo();
$linksperpage = $this->linksPerPage ? $this->linksPerPage : $pages;
$start = 0;
for($i=1; $i <= $pages; $i+=$linksperpage){
if($this->rs->AbsolutePage() >= $i){
$start = $i;
}
}
$s = '';
$end = $start+$linksperpage-1;
if($end > $pages) $end = $pages;
if ($this->startLinks && $start > 1) {
$pos = $start - 1;
$s .= '<a href='.$this->currLink.$this->id.'='.$pos.'>'.$this->startLinks.'</a> ';
}
for($i=$start; $i <= $end; $i++) {
if ($this->rs->AbsolutePage() == $i)
$s .= '<font color='.$this->linkSelectedColor.'><b>'.$i.'</b></font> ';
else
$s .= '<a href='.$this->currLink.$this->id.'='.$i.'>'.$i.'</a> ';
}
if ($this->moreLinks && $end < $pages)
$s .= '<a href='.$this->currLink.$this->id.'='.$i.'>'.$this->moreLinks.'</a> ';
return $s;
}
/**
* 下一页链接
*
* @param Boolean
*
* @return string
* @access private
*/
function _renderNext($anchor=true){
if ($anchor) {
$s = '<a href="'.$this->currLink.$this->id.'='.($this->rs->AbsolutePage()+1).'">'.$this->next.'</a> ';
} else {
$s = "$this->next ";
}
return $s;
} /**
* 尾页链接
*
* @param Boolean
*
* @return string
* @access private
*/
function _renderLast($anchor=true){
if (!$this->DB->pageExecuteCountRows) return;
if ($anchor) {
$s = '<a href="'.$this->currLink.$this->id.'='.$this->rs->LastPageNo().'">'.$this->last.'</a>';
} else {
$s = "$this->last";
}
return $s;
}
}
?>
从函数到分页类
http://www.chinaunix.net/jh/27/181584.html
http://club.phpe.net/index.php?act=ST&f=6&t=6028&hl=扶虺&s=
$num 记录数
$perpage 一页多少条
$curr_page 当前页
$mpurl 链接地址function multi($num, $perpage, $curr_page, $mpurl) {
$multipage = '';
if($num > $perpage) {
$page = 10;
$offset = 2; $pages = ceil($num / $perpage);
$from = $curr_page - $offset;
$to = $curr_page + $page - $offset - 1;
if($page > $pages) {
$from = 1;
$to = $pages;
} else {
if($from < 1) {
$to = $curr_page + 1 - $from;
$from = 1;
if(($to - $from) < $page && ($to - $from) < $pages) {
$to = $page;
}
} elseif($to > $pages) {
$from = $curr_page - $pages + $to;
$to = $pages;
if(($to - $from) < $page && ($to - $from) < $pages) {
$from = $pages - $page + 1;
}
}
}
$multipage .= '<a href="'.$mpurl.'&page=1"><<</a> ';
for($i = $from; $i <= $to; $i++) {
if($i != $curr_page) {
$multipage .= '<a href="'.$mpurl.'&page='.$i.'">['.$i.']</a> ';
} else {
$multipage .= '<u><b>['.$i.']</b></u> ';
}
}
$multipage .= $pages > $page ? " ... <a href=\"$mpurl&page=$pages\"> [$pages] >></a>" : " <a href=\"$mpurl&page=$pages\">>></a>";
}
return $multipage;
}