Home > Backend Development > PHP Tutorial > Class 2 for displaying Oracle database records in pages_PHP tutorial

Class 2 for displaying Oracle database records in pages_PHP tutorial

WBOY
Release: 2016-07-21 16:10:33
Original
837 people have browsed it


//-----------------------------
// Work function
//---- ----------------------------

//Read records
//The main working function, according to the The given conditions read the corresponding records from the table
//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;$jif(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 be 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;


}
//--------------------------
// Pagination related
//----- -----------------------

//Display the current page and total number of pages
//This function is called after GetPage() .
function ThePage() {
echo "Page".$this->CPages."Page/Total".$this->TPages."Page";
}

//Show the page button
//This function should be called after the GetPage() function
//Display the next page and the previous page, and add the parameters to be passed

function Page( ) {
$k=count($this->PageQuery);
$strQuery=""; //Generate a parameter string to pass
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 grouping
//-------------------- ----------------
//Display 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$next=( $ne!=-1)?( ($ne-1)*$this->MaxLine):(0);

$k=count($this->PageQuery);
$strQuery=""; //Generate a parameter string to pass
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
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/314253.htmlTechArticle//--------------------- ---------- // Work function //-------------------------------- // Read records //Main working function, read the corresponding records from the table according to the given conditions //Return...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template