分页组件 PHP5+MSSQL
<? class pagerecordset { private $cn; private $rs; private $totalpage = 0; private $totalrecord = 0; private $bpos = 1; private $epos = 1; private $row = null; private $firstpage = 1; private $prevpage = 1; private $nextpage = 1; private $lastpage = 1; public $pageindex = 1; public $pagerecordcount = 10; public function __construct() { $ip = func_get_arg(0); $uid = func_get_arg(1); $pwd = func_get_arg(2); $this->cn = mssql_connect($ip , $uid , $pwd) or die("Connection creation fail!"); } function __destruct() { } public function fetch($sql) { $this->rs = mssql_query($sql) or die("Query execution fail!"); $this->totalrecord = mssql_num_rows($this->rs); if ($this->totalrecord == 0) { } else { $this->totalpage = ceil($this->totalrecord / $this->pagerecordcount); $this->firstpage = 1; $this->lastpage = $this->totalpage; $this->prevpage = $this->pageindex - 1; $this->nextpage = $this->pageindex + 1; if ($this->prevpage < 1) { $this->prevpage = $this->lastpage; } if ($this->nextpage > $this->lastpage) { $this->nextpage = $this->firstpage; } $this->bpos = ($this->pageindex - 1) * $this->pagerecordcount; $this->epos = $this->bpos + $this->pagerecordcount; if ($this->epos > $this->totalrecord) { $this->epos = $this->totalrecord - $this->bpos + $this->bpos; } } mssql_data_seek($this->rs , $this->bpos) or die("Head locate fail!"); } public function read() { $returnval = false; if ($this->bpos < $this->epos) { $this->row = mssql_fetch_array($this->rs); $this->bpos++; $returnval = true; } return $returnval; } public function getfield($fieldname) { $returnval = ""; $returnval = $this->row[$fieldname]; return $returnval; } public function getposition() { $returnval = -1; $returnval = $this->bpos; return $returnval; } private function errmsg($funcbody , $errdescription) { $returnval = ""; $returnval += "<div style='padding:5px; background:#ffd700; color:#000; font-family:Verdana; font-size:11px;'>"; $returnval += " <div>Fundation:<strong>" + $funcbody + "</strong></div>"; $returnval += " <div>Description:" + $errdescription + "</div>"; $returnval += "</div>"; return $returnval; } public function shownavigation($pagequery , $otherquery) { $html = ""; $html .= "<div style=\"text-align:center; padding:5px;\">"; $html .= " <div>"; $html .= " <a href=\"?" . $pagequery . "=" . $this->firstpage . $otherquery . "\" style=\"font-family:Webdings; font-size:12px;\">9</a>"; $html .= " <a href=\"?" . $pagequery . "=" . $this->prevpage . $otherquery . "\" style=\"font-family:Webdings; font-size:12px;\">7</a>"; $html .= " " . $this->pageindex; $html .= " /"; $html .= " " . $this->lastpage; $html .= " <a href=\"?" . $pagequery . "=" . $this->nextpage . $otherquery . "\" style=\"font-family:Webdings; font-size:12px;\">8</a>"; $html .= " <a href=\"?".$pagequery."=".$this->lastpage.$otherquery."\" style=\"font-family:Webdings; font-size:12px;\">:</a>"; $html .= " </div>"; $html .= "</div>"; echo($html); } public function release() { mssql_free_result($this->rs) or die("Recordset destroy fail!"); mssql_close($this->cn) or die("Connection close fail!"); } } ?>
posted on 2005-07-17 19:19 ShineWayCN 阅读(770) 评论(0) 编辑 收藏 举报