The class, which has been modified from Erquan to the ODBC sub-page, adds some functionality, similar to this forum
Source: Internet
Author: User
odbc| pagination
Class pages{
var $cn; Connecting database Cursors
var $d; Cursors that connect data tables
var $result; Results
var $dsn; DSN source
var $user; User name
var $pass; Password
var $total; Total Records
var $pages; Total pages
var $onepage; Number of bars per page
var $page; Current page
var $fre; Previous page
var $net; Next page
var $i; Control each page display
##############################
######## Query for Tables #########
function Getdo ($sql) {//query data from tables
$this->d= @odbc_do ($this->cn, $sql);
if (! $this->d) {
$error = "A small error occurred while querying ...";
$this->getmess ($error);
}
return $this->d;
}
#################################
######## The total amount of data in the table #########
function Gettotal ($sql) {
$this->sql= $sql;
$dT = $this->getdo ($this->sql); Number of cursors to be evaluated
$this->total=odbc_result ($dT, "total"); Why not $this->d,total as a field here
$this->total= @odbc_num_rows ($dT); Should nag eldest brother's opinion, Odbc_num_rows cannot use, do not know why, return to 1
return $this->total;
}
##############################
######## Query for Tables #########
function GetList ($sql, $onepage, $page) {
if ($page <> "" and $page <1)//When this page is less than processed
$page = 1;
$this->s= $sql;
$this->onepage= $onepage; Number of records displayed per page
$this->page= $page; Pages
$this->dlist= $this->getdo ($this->s); cursors that connect tables
$this->pages=ceil ($this->total/$this->onepage); Calculates the smallest integer greater than the specified number
if ($this->page> $this->pages)//When this page is larger than the maximum page processing
$this->page= $this->pages;
if ($this->pages==0)
$this->pages++; Cannot take to page No. 0
if (!isset ($this->page))
$this->page=1;
$this->fre = $this->page-1; The number of pages to display
$this->nxt = $this->page+1;
$this->nums= ($this->page-1) * $this->onepage;
return $this->dlist;
}
##############################
function Getfetch_row ($dList) {
Return Odbc_fetch_row ($dList);
}
##############################
function GetResult ($dList, $num) {
Return Odbc_result ($dList, $num);
}
##############################
######## page ################
function Getfanye () {
$str = "";
if ($this->page!=1)
$str. = "<form name=go2to form method=post action= '". $PHP _self. "' ><a href= ". $PHP _self."? page=1> home </a><a href= ". $PHP _self."? Page= ". $this->fre." > front page </a> ";
Else
$str. = "<font color=999999> first page </font>";
if ($this->page< $this->pages)
$str. = "<a href=". $PHP _self. "? Page= ". $this->nxt." > Back Page </a> ";
Else
$str. = "<font color=999999> after page </font>";
if ($this->page!= $this->pages)
$str. = "<a href=". $PHP _self. "? Page= ". $this->pages." > Last </a> ";
Else
$str. = "<font color=999999> last </font>";
####################################
######## to perform the ######### of submitting form
function Check ()
{
if (isNaN (Go2to.page.value))
echo "Javascript:alert (please fill in the correct page!) ');";
else if (go2to.page.value== "") {
echo "Javascript:alert (' Please enter the number of pages to go!") ');";
}
else{
Go2to.submit ();
}
}
function Getnums () {//per page initial record number
return $this->nums;
}
function Getonepage () {//number of actual bars per page
return $this->onepage;
}
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