文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>分页显示类

分页显示类

时间:2006-05-11  来源:TX


$p->file="ttt.php";  //设置文件名,默认为当前页
$p->pvar="pagecount"; //设置页面传递的参数,默认为p
$p->setvar(array(
"a" => '1',
"b" => '2'
));      //设置要传递的参数,要注意的是此函数必须要在 set 前使用,否则变量传不过去
$p->set(20,2000,1);  //设置相关参数,共三个,分别为'页面大小'、'总记录数'、'当前页(如果为空则自动读取GET变量)'
$p->output(0);   //输出,为0时直接输出,否则返回一个字符串
echo $p->limit();  //输出Limit子句。在sql语句中用法为 "SELECT * FROM TABLE LIMIT {$p->limit()}";
---------------------------------------------------------------------------*/
//
class show_page {
/*---------------------------------------------------------------------------*/
# 页面输出结果
var $output;
/*---------------------------------------------------------------------------*/
# 使用该类的文件
var $file;
/*---------------------------------------------------------------------------*/
# 页数传递变量
var $pvar = "p";
/*---------------------------------------------------------------------------*/
# 页面大小
var $psize;
/*---------------------------------------------------------------------------*/
# 当前页面
var $curr;
/*---------------------------------------------------------------------------*/
# 要传递的变量
var $varstr;
/*---------------------------------------------------------------------------*/
# 总页数
var $tpage;
//add by
[email protected]
//首页字串
var $beginPageStr = "首页";
//前一页字串
var $prevPageStr = "前一页";
//共多少页(多少条)字串
var $totalPageStr = "共%s页(%s条)";
//当前多少页字串
var $curPageStr = "当前第%s页";
//后一页字串
var $nextPageStr = "后一页";
//尾页字串
var $endPageStr = "尾页";
function set($pagesize=20,$total,$current=false) {
  //global $HTTP_SERVER_VARS,$HTTP_GET_VARS; //delete this line, modify by
[email protected]
  $this->tpage = ceil($total/$pagesize);
  //if (!$current) {$current = $HTTP_GET_VARS[$this->pvar];} //modify this line as below to support >= PHP4.3.4, modify by
[email protected]
  if (!$current) {$current = $_GET[$this->pvar];}
  if ($current>$this->tpage) {$current = $this->tpage;}
  if ($current
  $this->curr  = $current;
  $this->psize = $pagesize;
  //if (!$this->file) {$this->file = $HTTP_SERVER_VARS['PHP_SELF'];} //modify this line as below to support >= PHP4.3.4, modify by
[email protected]
  if (!$this->file) {$this->file = $_SERVER['PHP_SELF'];}
  if ($this->tpage > 1) {
   //提供两种形式的分页 modify by
[email protected]
   //输出的分页形式:首页 前一页 共782页(11716条) 当前第2页 后一页 尾页
   if($current == 1)
   {
    $this->output .= "$this->beginPageStr ";
    $this->output .= "$this->prevPageStr ";
   }
   else if($current > 1)
   {
    $this->output .= 'file.'?'.$this->pvar.'=1'.($this->varstr).'>'.$this->beginPageStr.' ';
    $this->output.='file.'?'.$this->pvar.'='.($current-1).($this->varstr).'>'.$this->prevPageStr.' ';
   }
   $fontPre = "";
   $fontAft = "";
   $totalPageStrTmp = sprintf($this->totalPageStr, $fontPre.$this->tpage.$fontAft, $fontPre.$total.$fontAft);
   $this->output .= $totalPageStrTmp." ";
   //$this->output.="共".$this->tpage."页(".$total."条) ";
   $fontPre = "";
   $curPageStrTmp = sprintf($this->curPageStr, $fontPre.$current.$fontAft);
   $this->output .= $curPageStrTmp." ";
   //$this->output.="当前第".$current."页 ";
   if ($currenttpage) {
    $this->output.='file.'?'.$this->pvar.'='.($current+1).($this->varstr).'>'.$this->nextPageStr.' ';
    $this->output .= "file."?".$this->pvar."=".($this->tpage).($this->varstr).">".$this->endPageStr."";
   }
   else if($current == $this->tpage)
   {
    $this->output .= "$this->nextPageStr ";
    $this->output .= "$this->endPageStr ";
   }
   
   
   //输出的分页形式:共757页:[][>>][>>>]
   /*$this->output.="共".$this->tpage."页:";
            
   if ($current>10) {
    $this->output.='file.'?'.$this->pvar.'=1'.($this->varstr).' title="第一页">[';
    $this->output.='file.'?'.$this->pvar.'='.($current-10).($this->varstr).' title="前十页">[';
   }
            if ($current>1) {
    $this->output.='file.'?'.$this->pvar.'='.($current-1).($this->varstr).' title="前一页">[ ';
   }
   &nbs

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载