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

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

##############################
######## 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>";

$str. = "Total", $this->pages. " Page ";
$str. = "<font color= ' 000064 ' > go to <input type= ' text ' name= ' page ' size=2 maxlength=3 ' style=; Color: #00006A; position:relative; Height:18 ' value= '. $this->page. " > Page </font> ";
$str. = "<input class=button type= ' button ' value= ' Determine ' Onclick=check ' () style= ' font-family: XXFarEastFont-Arial; font-size:9pt; Color: #000073; position:relative; Height:19 ' ></form> ';
return $str;
}

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

function Geti () {//temporarily unused
$this->i= $this-pageone* ($this->page-1)
return $this->i;
}

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

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

<?php
Test program
$PG =new Pages ();
$PG->getconnect ("DSN", "User", "password");
$PG->gettotal ("SELECT count (*) as Total from Bul_file"); Total number of student tables
$pg->getlist ($sql, 3, $page);
if ($pg->getnums ()!=0) {
For ($i =0 $i < $PG->getnums (); $pg->getfetch_row ($pg->dlist), $i + +); Ditto
}
echo "<table width=\" 400\ border=1 cellspacing=\ "0\" cellpadding=\ "0\" bordercolordark=\ "#FFFFFF \" Bordercolorlight=\ "#000000 >";
echo $pg->getfanye ();
echo "</td></tr></table>";
echo "<table width=\" 400\ "border=\" 1\ "cellspacing=\" 0\ "cellpadding=\" 0\ "bordercolordark=\" "#FFFFFF \" Bordercolorlight=\ "#000000 >";
echo "<tr bgcolor=\" #CCFF99 \ "><td width=\" 5%\ "><font face=\" official script \ "size=\" 4\ "><div align=\" center \ ">ID</div></font></td> <td width=\" 50%\ "><font face=\" official script \ "size=\" 4\ "><div Align=\ "Center\" > title </div></font></td> <td width=\ "30%\" ><font face=\ "official script \" size=\ "4\" ><div align= ' center ' > Date </div></font></td> </tr>\ ';
$i = 1;
while ($pg->getfetch_row ($pg->dlist)) {
$PG->getnums ();
echo "<tr><td width=\" 5%\ ">". ($pg->nums+ $i). " &LT;/A&GT;&LT;/TD&GT;&LT;TD width=\ "50%\" ><div align= ' center ' ><a href=\ ' list_bul.php?id= '. $PG-> GetResult ($pg->dlist,1). " \ "target=\" Left\ ">". $pg->getresult ($pg->dlist,2). " &LT;/A&GT;&LT;/DIV&GT;&LT;/TD&GT;&LT;TD width=\ "30%\" ><div align= ' center ' > '. substr ($PG->getresult ($ pg->dlist,4), 1,10). " </div></td></tr> ";
if ($i = = $pg->getonepage ()) {//jump out of the loop
Break
}
$i + +;
?>

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.