欢迎光临
我们一直在努力

分页显示Oracle数据库记录的类之二-PHP教程,数据库相关

建站超值云服务器,限时71元/月

//——————————–

// 工作函数

//——————————–

//读取记录

// 主要工作函数,根据所给的条件从表中读取相应的记录

// 返回值是一个二维数组,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

}

?>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 分页显示Oracle数据库记录的类之二-PHP教程,数据库相关
分享到: 更多 (0)

相关推荐

  • 暂无文章