⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mydatagridclass.php

📁 完全用PHP来完成的办公自动化系统
💻 PHP
字号:
<!--myDataGridClass.php:数据分页显示类------------------------------------>
<?php
/********************************************* 
类名: myDataGridClass
功能:分页显示MySQL数据库中的数据 
***********************************************/ 
class myDataGridClass{ 
	//属性
	var $sql;							//所要显示数据的SQL查询语句 
	var $max_line;				//每页显示最多行数 
	
	var $begin_record;			//所要显示记录的首行序号
	var $total_records;			//记录总数 
	var $current_records;		//本页读取的记录数 
	var $result;						//读出的结果 
	
	var $total_pages;			//总页数  
	var $current_page;			//当前页数

	//方法
/********************************************* 
构造函数:__construct()
输入参数:			
		$pmax_line:每页显示最多行数	
***********************************************/ 
function myDataGridClass($pmax_line)
{ 
	$this->max_line=$pmax_line; 
	$this->begin_record=0;
} 

/********************************************* 
构造函数:__destruct()
输入参数:			
***********************************************/ 
function __destruct()
{
	
}
		
/********************************************* 
get函数:__get()
***********************************************/ 
function __get($property_name)
{  
	 if(isset($this->$property_name)) 
	 { 
			return($this->$property_name); 
	 } 
	 else 
	 { 
			return(NULL); 
	 } 
}
 
/********************************************* 
set函数:__set()
***********************************************/ 
function __set($property_name, $value) 
{ 
	 $this->$property_name = $value; 
} 

/********************************************* 
函数名:read_data
功能:	根据SQL查询语句从表中读取相应的记录
返回值:属性二维数组result[记录号][字段名]
***********************************************/ 
function read_data()
{ 
	$psql=$this->sql; 
	$this->begin_record=$_SESSION["g_begin_record"];
	
	//查询数据,数据库链接等信息应在类调用的外部实现
	$result=mysql_query($psql) or die(mysql_error()); 
	$this->total_records=mysql_num_rows($result); 
	
	//利用LIMIT关键字获取本页所要显示的记录
	if($this->total_records>0) 
	{
		$psql=$psql.	" LIMIT ".$this->begin_record." , ".$this->max_line; 
		//echo $psql;
		
		$result=mysql_query($psql) or die(mysql_error()); 
		$this->current_records=mysql_num_rows($result); 
		
		//将查询结果放在result数组中
		$i=0; 
		while($row=mysql_fetch_Array($result))
		{ 
			$this->result[$i]=$row; 
			$i++; 
		} 
	}
}


/********************************************* 
函数名:navigate()
功能:	显示首页、下页、上页、未页
***********************************************/ 
function navigate() 
{
	//获取总页数、当前页信息
	echo "<hr>";
	echo "<hr>";
	$this->total_pages=ceil($this->total_records/$this->max_line); 
	$this->current_page=$this->begin_record/$this->max_line+1; 
	echo "<div align=center>";
	echo "<font color = red size ='4'>第".$this->current_page."页/共".$this->total_pages."页</font>"; 
	echo "    ";
	
	//获取将要导航到的分页的初始记录号
	$first=0; 
	$next=$this->begin_record+$this->max_line; 
	$prev=$this->begin_record-$this->max_line; 
	$last=($this->total_pages-1)*$this->max_line; 

	//生成导航链接
	if($this->begin_record>=$this->max_line) 
		echo "<A href=".$_SERVER['PHP_SELF']."?begin_record=".$first.">首页</A>|"; 
	if($prev>=0) 
		echo "<A href=".$_SERVER['PHP_SELF']."?begin_record=".$prev.">上一页</A>|"; 
	if($next<$this->total_records) 
		echo "<A href=".$_SERVER['PHP_SELF']."?begin_record=".$next.">下一页</A>|"; 
	if($this->total_pages!=0 && $this->current_page<$this->total_pages) 
		echo "<A href=".$_SERVER['PHP_SELF']."?begin_record=".$last.">末页</A>"; 		
	echo "</div>";
}

} 
?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -