php利用模板分頁程式(帶demo示範);(1/3)

來源:互聯網
上載者:User

//page.class.php


class page{

 var $currentpage;
 var $leftoffset;
 var $rightoffset;
   
 var $totalpage;//總頁數
 var $recordcount;//總記錄數
 var $pagesize;//每頁顯示條數

 var $pageurl;
 var $hypelink;

 var $template;
 var $tpl;
 var $tagitems=array();
 var $tagvalues=array();

 var $sqlquery;

 //建構函式
 function page($currentpage=1,$pagesize=5,$leftoffset=2,$rightoffset=7,$pageurl="?page="){
  echo "分頁類開始";
  $this->currentpage=ceil(abs(@$currentpage+0));
  (empty($this->currentpage))?$this->currentpage=1:$this->currentpage=$this->currentpage;
  $this->pagesize=ceil(abs(@$pagesize+0));
  (empty($this->pagesize))?$this->pagesize=5:$this->pagesize=$this->pagesize;
  $this->leftoffset=ceil(abs(@$leftoffset+0));
  (empty($this->leftoffset))?$this->leftoffset=2:$this->leftoffset=$this->leftoffset;
  $this->rightoffset=ceil(abs(@$rightoffset+0));
  (empty($this->rightoffset))?$this->rightoffset=7:$this->rightoffset=$this->rightoffset;
  $this->pageurl=$pageurl;

  $this->setdefaulttagvalue();
 }
   
 //取得記錄總數
 //$sql="select count(id) as n from table";
 function getrecordcount($sql,$conn){
  $query=@mysql教程_query($sql,$conn);
  if(!$query){echo "執行sql語句失敗";exit();}
  while($rs=mysql_fetch_row($query)){
   $this->recordcount=$rs[0];//取得記錄總數
  }
  $this->totalpage=ceil($this->recordcount / $this->pagesize);//計算總頁數
  if($this->currentpage > $this->totalpage){$this->currentpage=$this->totalpage;}//判斷當前頁是否大於總頁數
  mysql_free_result($query);
 }
   
 //select * from tb p->setlimit();
 function setlimit(){
  $limit="limit ".($this->currentpage-1)*$this->pagesize;
  $limit.=",$this->pagesize";
  return $limit;
 }
 
 function executesql($sql,$conn){
  if(!$sql||!$conn){echo "參數傳遞錯誤";return false;}
     $this->sqlquery=mysql_query($sql,$conn);
     if(!$this->sqlquery){echo "執行sql語句失敗";return false;}
 }
 function recordset(){
  return mysql_fetch_array($this->sqlquery);
 }
   
 //取得模板內容
 function gettemplate($filedir){
  if(file_exists($filedir)){
   $f=fopen($filedir,"r");
   $this->template=fread($f,filesize($filedir));
  }else{
   echo "擷取模板檔案失敗...檔案不存在";
   exit();
  }
  //取得區塊內容
  $start=strpos($this->template,"<!--templatebegin-->");
  $end=strpos($this->template,"<!--templateend-->");
  $this->tpl=substr($this->template,$start+strlen("<!--templatebegin-->"),$end-$start-strlen("<!--templateend-->")-2);
  if($this->tpl==""){echo "模板內容為空白,請檢查標籤設定是否正確。";exit();}
  //echo $this->tpl;
 }

首頁 1 2 3 末頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.