Paging oracle database implementation_PHP tutorial
- WBOYOriginal
- 2016-07-13 10:46:27972browse
This article will introduce the paging function of the database implemented by PHP and orace database. Students in need can take a look below.
The code is as follows
代码如下 |
复制代码 |
include "/maya/inc/dbconn.php";
$sql="select max(rownum) from xqhtest where id<50";
$stmt=ociparse($gConn,$sql);
ociexecute($stmt);
ocifetch($stmt);
$rowcount=ociresult($stmt,1);
ocifreestatement($stmt);
echo("共有".$rowcount."条记录 n");
$recordperpage=15; //每页显示多少条记录
$pages=ceil($rowcount/$recordperpage); //总页数
echo("共有".$pages."页 n");
?>
id | name |
//判断偏移量参数是否传递给了脚本,如果没有就使用默认值0
if (empty($offset))
{
$offset=1;
}
$currentpage=ceil($offset/$recordperpage); //显示当前页
echo("当前页:".$currentpage." n");
$endset=$offset+$recordperpage;
$stmt2=ociparse($gConn,"SELECT rownum,id,name FROM xqhtest WHERE id<50 and rownum<".$endset." minus select rownum,id,name from xqhtest where id<50 and rownum<".$offset);
//echo "SELECT id,name FROM xqhtest WHERE rownum<".$endset." minus select id,name from xqhtest where rownum<".$offset." n";
ociexecute($stmt2);
//可以是任何sql语句,但select后面一定要有rownum,这是oracle特有的!
while (ocifetch($stmt2))
{
echo(" ".ociresult($stmt2,"ID")." | ".ociresult($stmt2,"NAME")." | n");
//换成你用于显示返回记录的代码
}
//要写出到所有页面的链接
print "
";
for ($i=1; $i <= $pages; $i++)
{
$newoffset=($recordperpage*($i-1))+1;
print "$i n";
}
print " ";
$nextoffset=$recordperpage*$currentpage+1;
$prevoffset=$recordperpage*($currentpage-2)+1;
//判断是否需要上一页连接
if (($currentpage>1) && ($currentpage<=$pages))
{
print "上一页 n";
}
|
|
Copy code |
|
include "/maya/inc/dbconn.php";
$sql="select max(rownum) from xqhtest where id<50";
$stmt=ociparse($gConn,$sql);
ociexecute($stmt);
ocifetch($stmt);
$rowcount=ociresult($stmt,1);
ocifreestatement($stmt);
echo("Total ".$rowcount." records
n");
$recordperpage=15; //How many records are displayed on each page
$pages=ceil($rowcount/$recordperpage); //Total number of pages
echo("Total".$pages."Page
n");
?>
id | name |
//Determine whether the offset parameter is passed to the script, if not, use the default value 0
if (empty($offset))
{
$offset=1;
}
$currentpage=ceil($offset/$recordperpage); //Display the current page
echo("Current page:".$currentpage."
n");
$endset=$offset+$recordperpage;
$stmt2=ociparse($gConn,"SELECT rownum,id,name FROM xqhtest WHERE id<50 and rownum<".$endset." minus select rownum,id,name from xqhtest where id<50 and rownum<" .$offset);
//echo "SELECT id,name FROM xqhtest WHERE rownum<".$endset." minus select id,name from xqhtest where rownum<".$offset."
n";
ociexecute($stmt2);
//It can be any SQL statement, but there must be rownum after select, which is unique to Oracle!
while (ocifetch($stmt2))
{
echo("".ociresult($stmt2,"ID")." | ".ociresult($stmt2,"NAME")." | n");
//Replace with the code you use to display the returned records
}
//To write links to all pages
print "
";
for ($i=1; $i <= $pages; $i++)
{
$newoffset=($recordperpage*($i-1))+1;
print "$i n";
}
print "
";
$nextoffset=$recordperpage*$currentpage+1;
$prevoffset=$recordperpage*($currentpage-2)+1;
//Determine whether a previous page connection is needed
if (($currentpage>1) && ($currentpage<=$pages))
{
print "
Previous page n";
}
http://www.bkjia.com/PHPjc/632939.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632939.htmlTechArticleThis article will introduce the paging function of the database implemented by PHP and orace database. Students who need it can take a look below. Bar. The code is as follows Copy the code html body ? include /maya/inc...
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn