分頁顯示Oracle資料庫記錄的類之二_php基礎

來源:互聯網
上載者:User

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

//讀取記錄
//主要工作函數,根據所給的條件從表中讀取相應的記錄
//傳回值是一個二維數組,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
}
?>
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.