Wrote an ODBC even MSSQL paging class, please advise one or two (original).

Source: Internet
Author: User
Tags dsn connect odbc mssql sql net return
odbc| Page | Original <!--two springs. NET-->
?
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

function GetConnect ($DSN, $user, $pass) {
$this->cn= @odbc_connect ($dsn, $user, $pass);
if (! $this-&GT;CN) {
$error = "Connection Database error";
$this->getmess ($error);
}
}

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;
}

function Gettotal ($sql) {
$this->sql= $sql;
$dT = $this->getdo ($this->sql); Number of cursors to be evaluated
$this->total=odbc_result ($dT, ' total '); why can't $this->d here?
return $this->total;
}

function GetList ($sql, $onepage, $page) {
$this->s= $sql;
$this->onepage= $onepage;
$this->page= $page;
$this->dlist= $this->getdo ($this->s); cursors that connect tables
$this->pages=ceil ($this->total/$this->onepage);
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;
if ($this->nums!=0) {
For ($this->i=0; $this->i< $pg->getnums (); Odbc_fetch_row ($this->dd), $this->i++);/ibid.
//}
$this->i=0;//Why is this part not encapsulated?
return $this->dlist;
}

function Getfanye () {
$str = "";
if ($this->page!=1)
$str. = "<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>";

$str. = "Total", $this->pages. " Page ";
$str. = "You are browsing <font color=red>". $this->page. " </font> page ";
return $str;
}

function Getnums () {
return $this->nums;
}

function Getonepage () {//number of actual bars per page
return $this->onepage;
}

function Geti () {
return $this->i;
}

function GetPage () {
return $this->page;
}

function Getmess ($error) {//Custom message
echo "<center> $error </center>";
Exit
}
}

$PG =new Pages ();
$PG->getconnect ("Lei", "sa", "star");
$PG->gettotal ("SELECT count (*) as Total from Xs"); Total number of student tables
$PG->getlist ("Select Xs_name from xs order by xs_id", 8, $page);
if ($pg->getnums ()!=0) {
For ($i =0 $i < $PG->getnums (); Odbc_fetch_row ($pg->dlist), $i + +);/ibid.
}
$i = 0;
while (Odbc_fetch_row ($PG->dlist)) {
$name =odbc_result ($pg->dlist, "Xs_name");
echo $name. " <br> ";
if ($i = = $pg->getonepage ()) {//jump out of the loop
Break
}
$i + +;
}
Echo$pg->getfanye ();
?>

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.