>  기사  >  php教程  >  分页显示Oracle数据库记录的类之二

分页显示Oracle数据库记录的类之二

WBOY
WBOY원래의
2016-06-21 09:08:54936검색

oracle|分页|数据|数据库|显示

//--------------------------------
// 工作函数
//--------------------------------

//读取记录
// 主要工作函数,根据所给的条件从表中读取相应的记录
// 返回值是一个二维数组,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
}
?>



성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.