搜尋
首頁php教程php手册自己写一个分页显示的类

分页|显示

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 "";
}
echo "";

for($i=$intPageBegin;$i{
if ($i%2==0)
{
$bgColor="#D2F0FF";
}
else
{
$bgColor="#ffffff";
}
echo "";
for($j=0;$jcols;$j++)
{
echo "";
}
echo "";
}
echo "
".$this->strFieldName[$m]."
".$this->ShowData($array,$i,$j)."
";
}

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);

?>



陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
3 週前By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解鎖Myrise中的所有內容
1 個月前By尊渡假赌尊渡假赌尊渡假赌

熱工具

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

強大的PHP整合開發環境

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

VSCode Windows 64位元 下載

VSCode Windows 64位元 下載

微軟推出的免費、功能強大的一款IDE編輯器

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具