PHP Oracle Database for paging _php tutorial

Source: Internet
Author: User
This article to introduce the PHP and Orace database to implement the paging function of the database, the following students can take a look at it.
The code is as follows 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 ("Shared". $rowcount. " Article Records
n ");
$recordperpage = 15; How many records are displayed per page
$pages =ceil ($rowcount/$recordperpage); Total pages
Echo ("Shared". $pages. " Page
n ");

?>


Determines whether the offset parameter is passed to the script, and if not, uses the default value of 0

if (empty ($offset))
{
$offset = 1;
}
$currentpage =ceil ($offset/$recordperpage); Show Current Page
Echo ("Current page:". $currentpage. "
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. "The minus select Id,name from Xqhtest where rownum<". $offse T. "
n ";
Ociexecute ($stmt 2);
can be any SQL statement, but there must be rownum behind Select, which is unique to Oracle!
while (Ocifetch ($stmt 2))

{
Echo ("

Replace the code you used to display the return record
}
To write a link to all pages
Print "

n ");
Id Name
". Ociresult ($stmt 2," ID ")." ". Ociresult ($stmt 2," NAME ")."


";


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 if a previous page connection is required
if ($currentpage >1) && ($currentpage <= $pages))
{
print "Prev n";
}

http://www.bkjia.com/PHPjc/632939.html www.bkjia.com true http://www.bkjia.com/PHPjc/632939.html techarticle This article to introduce the PHP and Orace database to implement the paging function of the database, the following students can take a look at it. The code below copies the code HTML body? Include/maya/inc ...

  • 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.