• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

分页组件PHP5+MSSQL

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
<?
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!");
	}

}
?>

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHPjava时间戳转php时间戳发布时间:2022-07-10
下一篇:
phpforeach跳出本次/当前循环与终止循环方法发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap