Example program to implement pagination with Php+oracle

Source: Internet
Author: User
Tags implement sql rowcount stmt
oracle| Program | pagination | example <body>
?
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 ("Shared". $rowcount. " Record <br>\n ");
$recordperpage = 15; How many records are displayed per page
$pages =ceil ($rowcount/$recordperpage); Total pages
Echo ("Shared". $pages. " Page <br>\n ");

?>
<table border=0><tr><td>id</td><td>name</td></tr>
?

Determine if the offset parameter is passed to the script, and if not, use the default value 0

if (empty ($offset))
{
$offset = 1;
}
$currentpage =ceil ($offset/$recordperpage); Show Current Page
Echo ("Current page:". $currentpage. " <br>\n ");
$endset = $offset + $recordperpage;

$stmt 2=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<." $offse T. " <br>\n ";
Ociexecute ($stmt 2);
can be any SQL statement, but there must be rownum behind the Select, which is unique to Oracle!
while (Ocifetch ($stmt 2))

{
Echo ("<tr><td>". Ociresult ($stmt 2, "ID"). " </td><td> ". Ociresult ($stmt 2," NAME ")." </td></tr>\n ");

For the code you used to display the return record.
}
To write a link to all pages
print "</table><br><br>";


for ($i =1; $i <= $pages; $i + +)
{
$newoffset = ($recordperpage * ($i-1)) +1;
Print "<a href=\" $PHP _self?offset= $newoffset \ "> $i </a> \ n";
}
print "<br>";

$nextoffset = $recordperpage * $currentpage +1;
$prevoffset = $recordperpage * ($currentpage-2) +1;
Determine if a previous page connection is required
if ($currentpage >1) && ($currentpage <= $pages))
{
Print "<a href=\" $PHP _self?offset= $prevoffset \ "> prev </a> \ n";
}

Determine if a next page connection is required
if ($pages!=0) && ($currentpage < $pages))
{
Print "<a href=\" $PHP _self?offset= $nextoffset \ "> Next </a> \ n";
}

Ocifreestatement ($stmt 2);
Ocilogoff ($gConn);
?>
</body>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.