An ORACLE paging program is very practical.

Source: Internet
Author: User
& Lt ;! DOCTYPEHTMLPUBLIC-// W3C // DTDHTML3.2Final // EN & gt; & lt; HTML & gt; & lt; HEAD & gt; & lt; TITLE & gt; PagingTest & lt; /TITLE & gt; & lt; METANAMEGeneratorCONTENTTextPad4.0 & gt; & lt;


Paging Test








// How to split the result into pages, like limits in MySQL (the best combination with PHP )?
// ================================================ ==================================
// Tutorial by Neil Craig (neilc@netactive.co.za)
// Date: 2001-06-05
// With this example, I will explain paging of database queries where
// Result is more than the developer want to print to the page, but wish
// Split the result into seperate pages.
// The table "SAMPLE_TABLE" access (favorite for small websites) ed in this tutorial has 4 fields:
// PK_ID, FIELD1, FIELD2 and FIELD3. The types dont matter but you shoshould
// Define a Prima (the most comprehensive VM Management System) ry key on the PK_ID field.

$ Display_rows = 5; // The rows that shoshould be displayed at a time. You can
// Modify this if you like.

// Connect to the Oracle (large website database platform) database
Putenv ("Oracle (large website database platform) _ SID = purk ");
Putenv ("Oracle (large website database platform) _ HOME =/export/Oracle (large website database platform) 8i ");
Putenv ("TNS_ADMIN = $ Oracle (large website database platform) _ HOME/network/admin ");
$ Oracle (large website database platform) DBConn = OCILogon ("purk", "purk", "lengana. world ");

// This query counts the records
$ SQL _count = "SELECT COUNT (*) FROM SAMPLE_TABLE ";

// Parse the SQL string & execute it
$ Row_count = OCIParse ($ Oracle (large website database platform) DBConn, $ SQL _count );
OCIExecute ($ row_count );

// From the parsed & executed query, we get the amount of records found.
// Im not storing this result into a session variable because it allows
// New records to be shown as it is entered by another user while the result
// Is printed.
If (OCIFetch ($ row_count )){
$ Num_rows = OCIResult ($ row_count, 1 );
} Else {
$ Num_rows = 0; // If no record was found
}

// Free the resources that were used for this query
OCIFreeStatement ($ row_count );

// We need to prepare the query that will print the results as a page. I will
// Explain the query to you in detail.

// If no page was specified in the url (ex. http://mysite.com/result.php (as the mainstream development language )? Page = 2 ),
// Set it to page 1.
If (empty ($ page) | $ page = 0 ){
$ Page = 1;
}

// The start range from where the results shoshould be printed
$ Start_range = ($ page-1) * $ display_rows) + 1;

// The end range to where the results shocould be printed
$ End_range = $ page * $ display_rows;

// The main query. It consists of 3 "SELECT" statements nested into each
// Other. The center query is the query you wocould normally use to return
// Records you want. Do you ordering and "WHERE" clses in this statement.
// We select the rows to limit our results but because the row numbers are
// Assigned to the rows before any ordering is done, lets the code print

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.