|
|
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已! |
|
恭喜您是本站第 1729071
位訪客!
登入 | 註冊
|
|
|
|
發表者 |
討論內容 |
冷日 (冷日) |
發表時間:2010/4/9 15:02 |
- Webmaster

- 註冊日: 2008/2/19
- 來自:
- 發表數: 15771
|
- [轉貼]村老師的分頁用物件
- 功能:換頁用物件
用法: 1.生成物件
$Chi_page= new Chi_Page(資料筆數,每頁筆數,目前頁數,連結網址) ;
2.秀出結果
echo $Chi_page->show_page();
程式碼如下:
<?php
#######################################################
### Script By 二林網管 紀明村 95.01.15
#######################################################
class Chi_Page {
var $tol;//總筆數
var $all_p;
var $page;//目前頁數
var $size;//每頁筆數
var $url;//連結網址
function Chi_Page($tol,$size,$page='',$url='') {
($page=='') ? $this->page=0:$this->page=$page;
($url=='') ? $this->url=$_SERVER[PHP_SELF]:$this->url=$url;
$this->size=$size;
// ($size=='') ? die("無法操作Chi_Page class"):$this->size=$size ;
$this->tol=$tol;
// if ($this->tol==''|| $this->tol==0) die("沒有資料,無法操作 Chi_Page class");
$this->all_p=ceil($this->tol/$this->size);
}
##################### 跳頁函式 ###########################
function show_page(){
if ($this->tol=='' ||$this->tol==0 || $this->size==''|| $this->size==0 ){
return "目前無資料!";
}
$tol=$this->all_p;
$now=$this->page;
$URL=$this->url;
($URL==$_SERVER[PHP_SELF]) ? $ln='?':$ln='&';
if ( $tol==1 ) return "";
if ( $tol==2 ) {
if ($now==0) {
$tt= $this->button('第1頁').$this->button('上頁').$this->button('下頁',$URL.$ln."page=1").
$this->button('最末頁',$URL.$ln."page=1");
}
if ($now==1) $tt= $this->button('第1頁',$URL.$ln."page=0").$this->button('上頁').$this->button('下頁');
}
if ( $tol>=3) {
$tol2=$tol-1;
if ($now==0) {
$tt=$this->button('第1頁').$this->button('上頁').$this->button('下頁',$URL.$ln."page=1").
$this->button('最末頁',$URL.$ln."page=".$tol2);
}
if ($now!=$tol2 && $now!=0)
$tt=$this->button('第1頁',$URL.$ln."page=0").
$this->button('上頁',$URL.$ln."page=".($now-1)).$this->button('下頁',$URL.$ln."page=".($now+1)).
$this->button('最末頁',$URL.$ln."page=".$tol2);
if ($now==$tol2)
$tt= $this->button('第1頁',$URL.$ln.'page=0').
$this->button('上頁',$URL.$ln."page=".($now-1)).$this->button('下頁').$this->button('最末頁');
}
$ss=$this->jump($URL,$ln,$tol,$now);
Return $this->button("共 $this->tol 筆").$tt.$ss;
}
function jump($URL,$ln,$tol,$now){
$ss="<select name='ch_page' size='1' class='small'
onChange=\"location.href='".$URL.$ln."page='+this.options[this.selectedIndex].value;\"
style='border:2px; background-color:#E5E5E5; font-size:10pt;color:#A52A2A' >";
for ($i=0;$i<$tol;$i++){
($now==$i) ? $cc=" selected":$cc="";
$ss.="<option value='$i' $cc>第".($i+1)."頁</option>\n";
}
$ss.="</select>";
return $ss;
}
function button($word,$URL=''){
$tt="<input type='button' value='$word' style=' border:1px;font-size:10pt' ";
($URL=='') ? $tt.=" disabled >":$tt.=" onclick=\"location.href='$URL'\" >";
return $tt;
}
function button3($word,$URL=''){
$tt="<input type='button' value='$word' ";
($URL=='') ?
$tt.=" disabled style=' background-color:#BFBFBF; font-size:10pt;color:red;' >":
$tt.=" onclick=\"location.href='$URL'\" style=' background-color:#BFBFBF; font-size:10pt;color:blue;' >";
return $tt;
}
function button2($word,$URL=''){
$tt="<input type='button' value='$word' ";
($URL=='') ?
$tt.=" disabled style=' background-color:#BFBFBF; font-size:10pt;color:red;' >":
$tt.=" onclick=\"location.href='$URL'\" style=' background-color:#BFBFBF; font-size:10pt;color:blue;' >";
return $tt;
}
}
/*
####### -----用法
$size=10;//每頁10筆
if ($_GET[page]=='') $Chi_page= new Chi_Page(500,$size,0) ;
else $page= new Chi_Page(500,$size,$_GET[page]) ;
echo $page->show_page();
*/
?>
原文出處:村老師的分頁用物件
|
|
|
討論串
- »
[轉貼]村老師的分頁用物件 (冷日 (冷日), 2010/4/9 15:02)
|