分页显示Oracle数据库记录的类之二
2018-09-07 13:32
//--------------------------------
// 工作函数
//--------------------------------
//读取记录
//主要工作函数,根据所给的条件从表中读取相应的记录
//返回值是一个二维数组,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
}
?>
上一篇:PHP单例模式与工厂模式详解
下一篇:实现“上一页”和“下一页按钮
文章标题:分页显示Oracle数据库记录的类之二
文章链接:http://soscw.com/index.php/essay/12688.html