& 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.
// 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
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