欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2023-11-25 23:21:04
//-------------------------------- // 工作函数 //---------...

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

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