分页|显示
class.php:
/*
-----------------------------------------------------------------------------------------------
名称:turnpage
作用:分页显示
成员函数:
entrance():类的入口,参数是所有成员函数的参数
selectdata($connection,$query):选择数据的函数,返回一个数组
showdata($array,$i,$j):显示各个字段值的函数,返回一个值
maketable($array,$intpagebegin,$intpageend):生成表格的函数,根据要显示的字段的个数生成相应的表格,参数分别是:数组,每页开始的信息序号,每页结束的信息序号
makelink($parameter=null):显示翻页的链接,参数可选
getfilename(): 取出当前执行文件名字,返回文件名
函数之间的关系:
-----------------------------------------------------------------------------------------------
*/
class turnpage
{
var $strarray;
var $cols;
var $rows;
var $strfieldname;
var $intpagebegin;
var $intpageend;
function entrance($connection,$query)
{
$myarray=$this->selectdata($connection,$query);
$this->getfilename();
$this->makelink($parameter=null);
$this->maketable($myarray,$this->intpagebegin,$this->intpageend);
}
function selectdata($connection,$query)
{
$result=@mysql_query($query,$connection) or die(unable to select the data!);
$intfieldsnum=mysql_num_fields($result);
for($a=0;$a{
$this->strfieldname[$a]=mysql_field_name($result,$a);
}
$this->cols=$intfieldsnum;
$count=0;
while($rows=mysql_fetch_row($result))
{
for($i=0;$i{
$data[$count][$i]=trim($rows[$i]);
}
$count++;
}
$this->rows=count($data);
$this->strarray=$data;
return $this->strarray;
}
function showdata($array,$i,$j)
{
return $array[$i][$j];
}
function maketable($array,$intpagebegin,$intpageend)
{
echo
;
echo ;
for($m=0;$mcols;$m++)
{
echo .$this->strfieldname[$m]. ;
}
echo
;
for($i=$intpagebegin;$i{
if ($i%2==0)
{
$bgcolor=#d2f0ff;
}
else
{
$bgcolor=#ffffff;
}
echo ;
for($j=0;$jcols;$j++)
{
echo .$this->showdata($array,$i,$j). ;
}
echo
;
}
echo
;
}
function getfilename()
{
$strpath=$_server[@#php_self@#];
$strfilename=trim(substr($strpath,(strrpos($strpath,/)+1)));
return $strfilename;
}
function makelink($parameter=null)
{
if($parameter==null)
{
$strparam=null;
}
else
{
$strparam=$parameter;
}
if($_get[intpage]==null)
{
$intpage=1;
}
else
{
$intpage=trim($_get[@#intpage@#]);
}
$intperpage=10;
$total=$this->rows;
$strfile=$this->getfilename();
$intpagebegin=$intperpage*$intpage-$intperpage;
$this->intpagebegin=$intpagebegin;
if ($intpage*$intperpage{
$intpageend=$intpagebegin+$intperpage;
}
else
{
$intpageend=$total;
}
$this->intpageend=$intpageend;
echo 信息总数:.$this->rows. ;
if($intpage>1)
{
echo 上一页;
}
echo ;
if ($intpage*$intperpage{
echo 下一页;
}
echo
;
}
}
?>
test.php:
include(../common/connection.php); //连接数据库的操作
include(../common/class.php); //把上面的文件包含近来
$query=select * from uphoto order by intuid asc;
$test=new turnpage;
$test->entrance($connection,$query);
?>