+ -
当前位置:首页 → 问答吧 → 偶的分页类,希望老大们指点

偶的分页类,希望老大们指点

时间:2007-03-15

来源:互联网

复制PHP内容到剪贴板
PHP代码:

<?php
/**
* @页面:main.class.php
* @功能:主要功能类
* @时间:
*/
####分页类####
class PageList
{
var $m_beginno;  //页码起始数
var $m_endno;    //页码结尾数
var $m_allno;    //页码(数组)
var $m_listno;   //页码数
var $m_pcount;   //总页数
var $m_cpage;    //当前页
var $m_prevpage; //上一页码
var $m_nextpage; //下一页码
var $m_r_count;  //总记录数
//构造函数(空间是PHP4的)
function PageList($m_pcount,$m_listno)//
{
  global $cpage,$r_count;//当前页,总页数
  $this->m_r_count = $r_count[0];
  $this->m_listno = $m_listno;
  $this->m_pcount = $m_pcount;
  $this->m_cpage  = $cpage;
  $this->m_prevpage = $this->m_cpage<=1 ? 1 : $this->m_cpage-1;
  $this->m_nextpage = $this->m_cpage>=$this->m_pcount ? $this->m_pcount : $this->m_cpage+1;
}
/**
  * @方法:getNums()
  * @功能:生成页码
  */
function getNums()
{
  if ( $this->m_pcount>$this->m_listno )
  {
   if ( $this->m_listno%2 == 1 )
   {
    $this->m_beginno = $this->m_cpage-($this->m_listno-1)/2;
    $this->m_beginno = $this->m_beginno<1 ? 1 : $this->m_beginno;
    $this->m_endno   = $this->m_cpage+($this->m_listno-1)/2;
    $this->m_endno   = $this->m_endno>$this->m_pcount ? $this->m_pcount : $this->m_endno;
   }
   if ( $this->m_listno%2 == 0 )
   {
    $this->m_beginno = $this->m_cpage-($this->m_listno/2-1);
    $this->m_beginno = $this->m_beginno<1 ? 1 : $this->m_beginno;
    $this->m_endno   = $this->m_cpage+$this->m_listno/2;
    $this->m_endno   = $this->m_endno>$this->m_pcount ? $this->m_pcount : $this->m_endno;
   }
   if ( $this->m_endno<$this->m_listno )
   {
    $this->m_endno = $this->m_endno+($this->m_listno-$this->m_endno);
   }
   if ( $this->m_endno-$this->m_beginno<$this->m_listno )
   {
    $this->m_beginno = $this->m_beginno-($this->m_listno-($this->m_endno-$this->m_beginno)-1);
   }
  }
  else
  {
   $this->m_beginno = 1;
   $this->m_endno   = $this->m_pcount;
  }
  for ( $i=$this->m_beginno;$i<=$this->m_endno;$i++ )
   {
    $this->m_allno[] = $i;
   }
  return $this->m_allno;
}
/**
  * @方法:pageShow()
  * @功能:输出页码列表
  */
function pageShow()
{
  echo ("<div id=\"pagelist\">\n");
  echo ("<ul>\n");
  echo ("<span>共{$this->m_r_count}条 第{$this->m_cpage}/{$this->m_pcount}页</span>\n");
  echo ("<li><a href=\"index.php?page=1\" title=\"第一页\"><<</a></li><li><a href=\"index.php?page={$this->m_prevpage}\" title=\"上一页\"><</a></li>");
  foreach ( $this->m_allno as $value)
  {
   $url = "<a href=\"index.php?page={$value}\" title=\"第{$value}页\">".$value."</a>";
   $url = $value==$this->m_cpage ? "<b>".$value."</b>" : $url;
   echo "<li>".$url."</li>\n";
  }
  echo ("<li><a href=\"index.php?page={$this->m_nextpage}\" title=\"下一页\">></a></li><li><a href=\"index.php?page={$this->m_pcount}\" title=\"最后一页\">>></a></li>");
  echo ("</ul>\n");
  echo ("</div>\n");
}
}

效果演示:http://www.06web.cn/gb

[ 本帖最后由 zwws 于 2007-3-15 11:04 编辑 ]

作者: zwws   发布时间: 2007-03-15

俺是新人,学习一下:lol

作者: wwwzlmj   发布时间: 2007-04-05