google分页的内核
时间:2006-01-17 来源:wleige
PHP代码:--------------------------------------------------------------------------------
//~~~~~~~~~~使用该类的文件
var $file;
//~~~~~~~~~~页面地址参数
var $para;
//~~~~~~~~~~页面地址
var $address;
//~~~~~~~~~~数据总数
var $total;
var $total_page;
//~~~~~~~~~~每页显示的数量
var $num_per_page=10;
//~~~~~~~~~~~~当前页
var $page_now;
var $offset;
//~~~~~~~~~~~~最末页
var $page_end;
var $offset_end;
//~~~~~~~~~~~~前一页
var $pre_page;
var $offset_pre;
//~~~~~~~~~~~~后一页
var $next_page;
var $offset_next;
//~~设置各项参数~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function set_num_per_page($num)
{
if($num>0)
{
$this->num_per_page=$num;
}
}
function set($file,$total,$offset,$para="")
{
$this->file=$file;
$this->total=$total;
$this->para=$para;
$this->offset=$offset;
$this->page_now=$this->offset/$this->num_per_page+1;
$pages=$total/$this->num_per_page;
if($pages==0) {$this->total_page=$pages+1;}
else {$this->total_page=ceil($pages);}
$this->page_end=$this->total_page;
$this->offset_end=$this->page2offset($this->page_end);
if($this->offset1) {$this->offset_pre =$this->offset-$this->num_per_page;} //前一页的offset
if($this->offset$this->offset_end){$this->offset_next =$this->offset+$this->num_per_page;} //前一页的offset
if($this->para==""){$this->address=$this->file.'?offset=';}
else {$this->address=$this->file.$this->para.'&offset=';}
//echo "0:".ceil(0);
//echo " pagenow:".$this->page_now;
//echo " pageend:".$this->page_end;
// echo " offsetend:".$this->offset_end;
}
function page2offset($page_no)
{
return ($page_no-1)*$this->num_per_page;
}
//~~输出开始~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//页码列表
function show_page_num_list($num=7,$now_form="",$list_class="")
{
$output="";
$num; //列表元素数
$now_form; //当前页形式,用{num}做替换,如"{num}"
$now_class; //当前页样式
$list_class; //列表样式
if($num%2==0){$num++;}
$lr_limit=($num-1)/2;
$l_page=$this->page_now;
$r_page=$this->page_now;
$output=str_replace("{num}", $this->page_now, $now_form);
for($i=0;$iaddress.$this->page2offset($l_page)."\" class=\"$list_class\">".$l_page." ".$output;
}
for($i=0;$ipage_end){break;}
$r_page++;
$output.=" address.$this->page2offset($r_page)."\" class=\"$list_class\">".$r_page." ";
}
return $output;
}
//上一页
function show_pre_page($format="上一页",$class="")
{
$output="";
if($this->offset0)
{
$output="address.$this->offset_pre."\" class=\"$class\">".$format."";
}
else
{
$output=$format;
}
return $output;
}
//下一页
function show_next_page($format="下一页",$class="")
{
$output="";
if($this->offset$this->offset_end)
{
$output="address.$this->offset_next."\" class=\"$class\">".$format."";
}
else
{
$output=$format;
}
return $output;
}
//首页
function show_first_page($format="首页",$class="")
{
$output="";
if($this->offset0)
{
$output="address."\" class=\"$class\">".$format."";
}
else
{
$output=$format;
}
return $output;
}
//末页
function show_last_page($format="末页",$class="")
{
$output="";
if($this->offset$this->offset_end)
{
$output="address.$this->offset_end."\" class=\"$class\">".$format."";
}
else
{
$output=$format;
}
return $output;
}
//跳转菜单
function show_jump_list($class="")
{
$output="跳至address."'+this.value\">";
for($i=1;$ipage_end;$i++)
{
$offset=$this->page2offset($i);
$output.="offset==$offset?" selected":"";
$output.=">第".$i."页";
}
$output.="";
return $output;
}
function show_total_page($format="总页数为({num})页")
{
return str_replace("{num}", $this->total_page, $format);
}
function show_total($format="共有记录({num})条")
{
return str_replace("{num}", $this->total, $format);
}
}
?>
//~~~~~~~~~~使用该类的文件
var $file;
//~~~~~~~~~~页面地址参数
var $para;
//~~~~~~~~~~页面地址
var $address;
//~~~~~~~~~~数据总数
var $total;
var $total_page;
//~~~~~~~~~~每页显示的数量
var $num_per_page=10;
//~~~~~~~~~~~~当前页
var $page_now;
var $offset;
//~~~~~~~~~~~~最末页
var $page_end;
var $offset_end;
//~~~~~~~~~~~~前一页
var $pre_page;
var $offset_pre;
//~~~~~~~~~~~~后一页
var $next_page;
var $offset_next;
//~~设置各项参数~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function set_num_per_page($num)
{
if($num>0)
{
$this->num_per_page=$num;
}
}
function set($file,$total,$offset,$para="")
{
$this->file=$file;
$this->total=$total;
$this->para=$para;
$this->offset=$offset;
$this->page_now=$this->offset/$this->num_per_page+1;
$pages=$total/$this->num_per_page;
if($pages==0) {$this->total_page=$pages+1;}
else {$this->total_page=ceil($pages);}
$this->page_end=$this->total_page;
$this->offset_end=$this->page2offset($this->page_end);
if($this->offset1) {$this->offset_pre =$this->offset-$this->num_per_page;} //前一页的offset
if($this->offset$this->offset_end){$this->offset_next =$this->offset+$this->num_per_page;} //前一页的offset
if($this->para==""){$this->address=$this->file.'?offset=';}
else {$this->address=$this->file.$this->para.'&offset=';}
//echo "0:".ceil(0);
//echo " pagenow:".$this->page_now;
//echo " pageend:".$this->page_end;
// echo " offsetend:".$this->offset_end;
}
function page2offset($page_no)
{
return ($page_no-1)*$this->num_per_page;
}
//~~输出开始~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//页码列表
function show_page_num_list($num=7,$now_form="",$list_class="")
{
$output="";
$num; //列表元素数
$now_form; //当前页形式,用{num}做替换,如"{num}"
$now_class; //当前页样式
$list_class; //列表样式
if($num%2==0){$num++;}
$lr_limit=($num-1)/2;
$l_page=$this->page_now;
$r_page=$this->page_now;
$output=str_replace("{num}", $this->page_now, $now_form);
for($i=0;$iaddress.$this->page2offset($l_page)."\" class=\"$list_class\">".$l_page." ".$output;
}
for($i=0;$ipage_end){break;}
$r_page++;
$output.=" address.$this->page2offset($r_page)."\" class=\"$list_class\">".$r_page." ";
}
return $output;
}
//上一页
function show_pre_page($format="上一页",$class="")
{
$output="";
if($this->offset0)
{
$output="address.$this->offset_pre."\" class=\"$class\">".$format."";
}
else
{
$output=$format;
}
return $output;
}
//下一页
function show_next_page($format="下一页",$class="")
{
$output="";
if($this->offset$this->offset_end)
{
$output="address.$this->offset_next."\" class=\"$class\">".$format."";
}
else
{
$output=$format;
}
return $output;
}
//首页
function show_first_page($format="首页",$class="")
{
$output="";
if($this->offset0)
{
$output="address."\" class=\"$class\">".$format."";
}
else
{
$output=$format;
}
return $output;
}
//末页
function show_last_page($format="末页",$class="")
{
$output="";
if($this->offset$this->offset_end)
{
$output="address.$this->offset_end."\" class=\"$class\">".$format."";
}
else
{
$output=$format;
}
return $output;
}
//跳转菜单
function show_jump_list($class="")
{
$output="跳至address."'+this.value\">";
for($i=1;$ipage_end;$i++)
{
$offset=$this->page2offset($i);
$output.="offset==$offset?" selected":"";
$output.=">第".$i."页";
}
$output.="";
return $output;
}
function show_total_page($format="总页数为({num})页")
{
return str_replace("{num}", $this->total_page, $format);
}
function show_total($format="共有记录({num})条")
{
return str_replace("{num}", $this->total, $format);
}
}
?>
相关阅读 更多 +