<? Php *************************************** * ***** TOracleViewPagev2.0 date: type update date for Oracle Database records displayed on pages from 2000-9-23: 2000-10-19 added the TopRecord display function. the number of records displayed on the first page is different from that on other pages. Sharetopemail: ycshowtop@21cn.com ************ <? Php
/*************************************** ******
TOracleViewPage v2.0
Date: 2000-9-23
Categories of Oracle Database records displayed on pages
Updated on: 2000-10-19
Added the TopRecord display function, allowing the number of records displayed on the first page to be different from those displayed on other pages.
Sharetop
Email: ycshowtop@21cn.com
**************************************** *******/
Class TOracleViewPage {
Var $ Table; // Table name
Var $ MaxLine; // number of lines per page
Var $ LinkId; // Database Connection number
Var $ Id; // sorting reference field
Var $ Offset; // record Offset
Var $ Total; // The Total number of records.
Var $ Number; // Number of records read on the current page
Var $ TopNumber; // number of records actually retrieved when reading a new record
Var $ Result; // read the Result
Var $ TopResult; // the result when the new record is read.
Var $ TheFirstPage; // specify the link to the first page.
Var $ StartRec; // specify the start record number on the second page
Var $ TPages; // The total number of pages.
Var $ CPages; // Current page number
Var $ TGroup;
Var $ PGroup; // Number of page numbers displayed on each page
Var $ CGroup;
Var $ Condition; // display conditions such as: where id = '$ ID' order by id desc
Var $ PageQuery; // display the parameters to be passed by page
//-------------------------------------
// The following constructor, destructor, and initialization function
//-------------------------------------
// Constructor
// Parameter: table name, maximum number of rows, reference fields by page, number of page numbers displayed on each page
Function TOracleViewPage ($ TB, $ ML, $ id ){
Global $ offset;
$ This-> Table = $ TB;
$ This-> MaxLine = $ ML;
$ This-> Id = $ id;
$ This-> StartRec = 0;
If (isset ($ offset) $ this-> Offset = $ offset;
Else $ this-> Offset = 0;
$ This-> Condition = "";
$ This-> TheFirstPage = NULL;
$ This-> PageQury = NULL;
}
// Initialization
// Parameter: user name, password, database
Function InitDB ($ user, $ password, $ db ){
If (PHP_ OS = "WINNT") $ dllid = dl ("php3_oci80.dll ");
$ This-> LinkId = OCILogon ($ user, $ password, $ db );
}
// Disconnect
Function Destroy (){
OCILogoff ($ this-> LinkId );
}
//-------------------------
// Set function
//-------------------------
// Set display conditions
// For example, where id = '$ ID' order by id desc
// It must be a string that complies with the SQL syntax (this string will be added after the SQL statement)
Function SetCondition ($ s ){
$ This-> Condition = $ s;
}
// Set the display quantity for each group
Function SetNumGroup ($ pg ){
$ This-> PGroup = $ pg;
}
// Set the homepage. if not, the homepage is NULL.
Function SetFirstPage ($ fn ){
$ This-> TheFirstPage = $ fn;
}
// Set the start record. If no record exists, the default value is 0.
Function SetStartRecord ($ org ){
$ This-> StartRec = $ org;
}
// Set transfer parameters
// Key parameter name value
// For example, setpagequery ("id", $ id). you can call this function multiple times if multiple parameters are to be passed.
Function SetPageQuery ($ key, $ value ){
$ Tmp [key] = $ key; $ tmp [value] = $ value;
$ This-> PageQuery [] = $ tmp;
}
//--------------------------------
// Get function
//--------------------------------
// Retrieve the total number of records
Function GetTotalRec (){
$ SQL = "SELECT Count (*) AS total FROM". $ this-> Table. "". $ this-> Condition;
$ Stmt = OCIParse ($ this-> LinkId, $ SQL );
$ Bool = OCIExecute ($ stmt );
If (! $ Bool ){
Echo "connection failed! ";
OCILogoff ($ this-> LinkId );
Exit;
}
Else {
OCIFetch ($ stmt );
$ This-> Total = OCIResult ($ stmt, 1 );
}
OCIFreeStatement ($ stmt );
}
// Retrieve the total number of pages and the current page
Function GetPage (){
$ This-> TPages = ceil ($ this-> Total/$ this-> MaxLine );
$ This-> CPages = ceil ($ this-> Offset/$ this-> MaxLine) 1;
}
// Obtain the total number of groups and the current group
Function GetGroup (){
$ This-> TGroup = ceil ($ this-> TPages/$ this-> PGroup );
$ This-> CGroup = ceil ($ this-> CPages/$ this-> PGroup );
}
//--------------------------------
// Work functions
//--------------------------------
// Read Records
// Main working function, which reads the corresponding records from the table based on the given conditions
// The returned value is a two-dimensional array. Result [record number] [field name]
Function ReadList (){
$ SQL = "SELECT * FROM". $ this-> Table. "". $ this-> Condition. "ORDER BY". $ this-> Id. "DESC ";
$ Stmt = OCIParse ($ this-> LinkId, $ SQL );
$ Bool = OCIExecute ($ stmt );
If (! $ Bool ){
Echo "connection failed! ";
OCILogoff ($ this-> LinkId );
Exit;
}
Else {
$ Ncols = OCINumCols ($ stmt );
For ($ I = 1; $ I <= $ ncols; $ I)
$ Column_name [$ I] = OCIColumnName ($ stmt, $ I );
$ K = 0;
For ($ j = 0; $ j <$ this-> StartRec $ this-> Offset; $ j) OCIFetch ($ stmt );
For ($ j = 0; $ j <$ this-> MaxLine; $ j ){
If (OCIFetch ($ stmt )){
$ K;
For ($ I = 1; $ I <= $ ncols; $ I)
$ Temp [$ column_name [$ I] = OCIResult ($ stmt, $ I );
$ This-> Result [] = $ temp;
}
Else break;
}
$ This-> Number = $ k;
}
OCIFreeStatement ($ stmt );
Return $ this-> Result;
}
// Read the latest record
// Topnum specifies the number of records to read
Function ReadTopList ($ topnum ){
$ SQL = "SELECT * FROM". $ this-> Table. "". $ this-> Condition. "ORDER BY". $ this-> Id. "DESC ";
$ Stmt = OCIParse ($ this-> LinkId, $ SQL );
$ Bool = OCIExecute ($ stmt );
If (! $ Bool ){
Echo "connection failed! ";
OCILogoff ($ this-> LinkId );
Exit;
}
Else {
$ Ncols = OCINumCols ($ stmt );
For ($ I = 1; $ I <= $ ncols; $ I)
$ Column_name [$ I] = OCIColumnName ($ stmt, $ I );
$ K = 0;
For ($ j = 0; $ j <$ topnum; $ j ){
If (OCIFetch ($ stmt )){
$ K;
For ($ I = 1; $ I <= $ ncols; $ I)
$ Temp [$ column_name [$ I] = OCIResult ($ stmt, $ I );
$ This-> TopResult [] = $ temp;
}
Else break;
}
$ This-> TopNumber = $ k;
}
OCIFreeStatement ($ stmt );
Return $ this-> TopResult;
}
//---------------------------
// Paging related
//---------------------------
// Display the current page and the total number of pages
// This function is called after GetPage.
Function ThePage (){
Echo "no.". $ this-> CPages. "page/total". $ this-> TPages. "page ";
}
// Display the Flip button
// This function must be called after the GetPage () function
// Display the next and last pages, and add the parameters to be passed
Function Page (){
$ K = count ($ this-> PageQuery );
$ StrQuery = ""; // Generate a parameter string to be passed
For ($ I = 0; $ I <$ k; $ I ){
$ StrQuery. = "&". $ this-> PageQuery [$ I] [key]. "=". $ this-> PageQuery [$ I] [value];
}
Return $ strQuery;
}
Function PrePage ($ strQuery ){
$ Prev = $ this-> Offset-$ this-> MaxLine;
If ($ prev> = 0)
Echo "<A href = $ PHP_SELF? Offset = ". $ prev. $ strQuery." class = newslink> Previous Page </A> ";
Else if ($ this-> TheFirstPage! = NULL)
Echo "<A href =". $ this-> TheFirstPage. "class = newslink> Previous Page </A> ";
Else echo "previous page ";
}
Function NexPage ($ strQuery ){
$ Next = $ this-> Offset $ this-> MaxLine;
$ K = $ this-> Total-$ this-> StartRec;
If ($ next <$ k)
Echo "<A href = $ PHP_SELF? Offset = ". $ next. $ strQuery." class = newslink> next page </A> ";
Else
Echo "next page ";
}
//------------------------------------
// Record Group
//----------------------------------
// Display Group
Function NumPage (){
$ First = ($ this-> CGroup-1) * ($ this-> PGroup) 1;
$ Last = ($ first $ this-> PGroup> $ this-> TPages )? ($ This-> TPages 1) :( $ first $ this-> PGroup );
$ Pr = ($ this-> CGroup-2> = 0 )? ($ This-> CGroup-2) * ($ this-> PGroup) 1) :(-1 );
$ Prev = ($ pr! =-1 )? ($ PR-1) * $ this-> MaxLine) :( 0 );
$ Ne = ($ this-> CGroup * $ this-> PGroup 1 <= $ this-> TPages )? ($ This-> CGroup * $ this-> PGroup 1) :(-1 );
$ Next = ($ ne! =-1 )? ($ Ne-1) * $ this-> MaxLine) :( 0 );
$ K = count ($ this-> PageQuery );
$ StrQuery = ""; // Generate a parameter string to be passed
For ($ I = 0; $ I <$ k; $ I ){
$ StrQuery. = "&". $ this-> PageQuery [$ I] [key]. "=". $ this-> PageQuery [$ I] [value];
}
If ($ first! = 1)
Echo "<A href = $ PHP_SELF? Offset = ". $ prev. $ strQuery."> </a> ";
For ($ I = $ first; $ I <$ last; $ I ){
If ($ this-> CPages! = $ I ){
$ Current = ($ i-1) * $ this-> MaxLine;
Echo "<A href = $ PHP_SELF? Offset = ". $ current. $ strQuery."> ". $ I." </a> ";
}
Else echo "<font color = # e00729>". $ I. "</font> ";
}
If ($ ne! =-1)
Echo "<A href = $ PHP_SELF? Offset = ". $ next. $ strQuery." >></a> ";
}
// ***** End class
}
?>