/*********************************************
Toracleviewpage v 2.0
Date: 2000-9-23
Pagination displays a class of Oracle database records
Update Date: 2000-10-19
Increases the functionality of the display Toprecord, allowing the first page to display a different number of records than other pages.
Author: sharetop
email:ycshowtop@21cn.com
***********************************************/
Class Toracleviewpage {
var $Table;//table name
var $MaxLine;//Show rows per page
var $LinkId;//database connection number
Var $Id;//row The Order Reference field
var $Offset;//Record offset
var $Total;//Records Total
var $Number//The number of records read on this page
Var $TopNumber;//number of records actually taken when reading a new record Br>var $Result; read out the result
Var $TopResult//Results when reading a new record
var $TheFirstPage;//special Specifies the link for the first page
Var $StartRec;//Specify the starting record number for the second page
var $TPages; Total number of pages
Var $CPages;//Current page
var $TGroup;
var $PGroup;//number of page numbers displayed per page
var $CGroup;
var $Condition;//display criteria such as: where id= ' $id ' ORDER by id DESC
var $PageQuery;//pagination display parameters to pass
//-------------------------------------
//The following constructors, destructors, and initialization functions
//-------------------------------------
//constructor
//Parameter: Table name, maximum number of rows, paged Reference field, page number displayed per 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
//Parameters: Username, 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
//such as: where id= ' $id ' The ORDER BY id DESC
//requirement is a string that conforms to the SQL syntax (this string will be added to the SQL statement)
function setcondition ($s) {
$this->condition= $s;
}
//Set the number of displays per group
function Setnumgroup ($pg) {
$this->pgroup= $pg;
}
//Set the home page, such as null
function Setfirstpage ($FN) {
$this->thefirstpage= $fn;
}
//Set the start record, if none, default 0
function Setstartrecord ($org) {
$this->startrec= $org;
}
//Set pass parameter
//Key parameter value
//: Setpagequery ("id", $id); This function can be called multiple times if there are multiple parameters to pass.
Function Setpagequery ($key, $value) {
$tmp [key]= $key; $tmp [value]= $value;
$this->pagequery[]= $tmp;
}
//--------------------------------
Get function
//--------------------------------
Total number of records taken
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);
}
Take total number of pages, current page
function GetPage () {
$this->tpages=ceil ($this->total/$this->maxline);
$this->cpages=ceil ($this->offset/$this->maxline) +1;
}
Take total group number, current group
function Getgroup () {
$this->tgroup=ceil ($this->tpages/$this->pgroup);
$this->cgroup=ceil ($this->cpages/$this->pgroup);
}
//--------------------------------
Work functions
//--------------------------------
Reading Records
Primary work function, reading the corresponding record from the table according to the conditions given
The return 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 records
Topnum specify 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;
}
//---------------------------
Page-related
//---------------------------
Show current page and total pages
This function is called after GetPage ().
Function thepage () {
echo "->cpages". $this. " Page/Total ". $this->tpages." Page ";
}
Show Page Buttons
This function is called after the GetPage () function
Displays the next page, the top page, and the parameters to pass
function Page () {
$k =count ($this->pagequery);
$strQuery = ""; Generate a string to pass the parameter number
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> prev </a>";
else if ($this->thefirstpage!=null)
echo "<a Href=". $this->thefirstpage. "Class=newslink> prev </a>";
else echo "Prev";
}
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 grouping
//----------------------------------
Show grouping
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 string to pass the parameter number
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
}
?>