程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> PHP綜合 >> 分頁顯示Oracle數據庫記錄的類之二

分頁顯示Oracle數據庫記錄的類之二

編輯:PHP綜合

//--------------------------------
// 工作函數
//--------------------------------

//讀取記錄
//主要工作函數,根據所給的條件從表中讀取相應的記錄
//返回值是一個二維數組,Result[記錄號][字段名]

function ReadList() {

$SQL="SELECT * FROM ".$this->Table." ".$this->Condition." ORDER BY ".$this->Id." DESC";

$stmt = OCIParse($this->LinkId,$SQL);
$bool = OCIExecute($stmt);
if (!$bool) {
echo "連接失敗!";
OCILogoff($this->LinkId);
exit;
}
else {
$ncols = OCINumCols($stmt);
for ( $i = 1; $i <= $ncols; $i++ )
$column_name[$i] = OCIColumnName($stmt,$i);
$k=0;

for($j=0;$j<$this->StartRec+$this->Offset;$j++) OCIFetch($stmt);
for($j=0;$j<$this->MaxLine;$j++){
if(OCIFetch($stmt)){
$k++;
for($i=1;$i<=$ncols;$i++)
$temp[$column_name[$i]]=OCIResult($stmt,$i);
$this->Result[]=$temp;
}
else break;
}
$this->Number=$k;

}
OCIFreeStatement($stmt);
return $this->Result;
}
//讀最新的記錄
//topnum指定要讀出的記錄數

function ReadTopList($topnum){

$SQL="SELECT * FROM ".$this->Table." ".$this->Condition." ORDER BY ".$this->Id." DESC";

$stmt = OCIParse($this->LinkId,$SQL);
$bool = OCIExecute($stmt);
if (!$bool) {
echo "連接失敗!";
OCILogoff($this->LinkId);
exit;
}
else {
$ncols = OCINumCols($stmt);
for ( $i = 1; $i <= $ncols; $i++ )
$column_name[$i] = OCIColumnName($stmt,$i);
$k=0;

for($j=0;$j<$topnum;$j++){
if(OCIFetch($stmt)){
$k++;
for($i=1;$i<=$ncols;$i++)
$temp[$column_name[$i]]=OCIResult($stmt,$i);
$this->TopResult[]=$temp;
}
else break;
}
$this->TopNumber=$k;

}
OCIFreeStatement($stmt);
return $this->TopResult;


}
//---------------------------
// 分頁相關
//---------------------------

//顯示當前頁及總頁數
//本函數在GetPage()後調用。
function ThePage() {
echo "第".$this->CPages."頁/共".$this->TPages."頁";
}

//顯示翻頁按鈕
//此函數要在GetPage()函數之後調用
//顯示下頁、上頁,並加上要傳遞的參數

function Page() {
$k=count($this->PageQuery);
$strQuery=""; //生成一個要傳遞參數字串
for($i=0;$i<$k;$i++){
$strQuery.="&".$this->PageQuery[$i][key]."=".$this->PageQuery[$i][value];
}

return $strQuery;
}

function PrePage($strQuery){
$prev=$this->Offset-$this->MaxLine;
if($prev>=0)
echo "<A href=$PHP_SELF?offset=".$prev.$strQuery." class=newslink>上一頁</A>";
else if($this->TheFirstPage!=NULL)
echo "<A href=".$this->TheFirstPage." class=newslink>上一頁</A>";
else echo "上一頁";
}

function NexPage($strQuery){
$next=$this->Offset+$this->MaxLine;
$k=$this->Total-$this->StartRec;
if($next<$k)
echo "<A href=$PHP_SELF?offset=".$next.$strQuery." class=newslink>下一頁</A>";
else
echo "下一頁";
}
//------------------------------------
// 記錄分組
//----------------------------------
//顯示分組
function NumPage() {
$first=($this->CGroup-1)*($this->PGroup)+1;
$last=($first+$this->PGroup > $this->TPages)? ($this->TPages+1):($first+$this->PGroup);
$pr=($this->CGroup-2>=0)?( ($this->CGroup-2)*($this->PGroup)+1 ):(-1);
$prev=($pr!=-1)?( ($pr-1)*$this->MaxLine):(0);
$ne=($this->CGroup*$this->PGroup+1<=$this->TPages)?($this->CGroup*$this->PGroup+1):(-1);
$next=($ne!=-1)?( ($ne-1)*$this->MaxLine):(0);

$k=count($this->PageQuery);
$strQuery=""; //生成一個要傳遞參數字串
for($i=0;$i<$k;$i++){
$strQuery.="&".$this->PageQuery[$i][key]."=".$this->PageQuery[$i][value];
}

if($first!=1)
echo "<A href=$PHP_SELF?offset=".$prev.$strQuery." > << </a>";
for($i=$first;$i<$last;$i++) {
if($this->CPages!=$i){
$current=($i-1)*$this->MaxLine;
echo "<A href=$PHP_SELF?offset=".$current.$strQuery." >".$i."</a> ";
}
else echo "<font color=#e00729>".$i."</font> ";
}
if($ne!=-1)
echo "<A href=$PHP_SELF?offset=".$next.$strQuery." > >> </a>";
}

//******end class
}
?>
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved