?? mydatagridclass.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 + -