Pagination shows the second class of Oracle database records

Source: Internet
Author: User
Tags bool exit count key prev stmt oracle database
oracle| Pagination | data | database | Display//--------------------------------
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
}
?>


Related Article

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.