当前位置:首页 > PHPêμày:PHP·?ò3′ú??

PHPêμày:PHP·?ò3′ú??

点击次数:1540  更新日期:2011-01-04
\n

<?php
/*
* ???t??£odatagridclass.php
* ×÷??£o?Dè??′
* ê±??£o2007-07-25
* ?èê?£o·?ò3àà
*/
error_reporting(0);
class datagridclass
{
private conn;
private result;
private resultArr = array();

public beginrecord = 0;
public totalrecords = 0;
public totalpages = 0;
public currentpage = 0;
public maxline = 0;
public maxlist = 0;


function __construct(pHost, pName, pPwd, pDbName, pMaxLine = 15, pMaxList = \'8)\'
{
this->conn = mysql_connect(pHost, pName, pPwd) or die(‘DataBase connecting false…’);
mysql_select_db(pDbName, this->conn) or die(‘Choice database false…’);

this->maxline = pMaxLine;
this->maxlist = pMaxList;
}//function __construct();


function __set(property_name, value)
{
this->property_name = value;
}//function __set();


function __destruct()
{
mysql_free_result(this->result);
mysql_close(this->conn);
}//function __destruct();


function readdata(pSql)
{
this->result = mysql_query(pSql, this->conn) or die(‘Select false…’);
this->totalrecords = mysql_num_rows(this->result);
if (!this->totalrecords)
{
return false;
}
else
{
this->totalpages = ceil(this->totalrecords / this->maxline);
pSql .= ‘ LIMIT ‘.this->beginrecord.’,’.this->maxline;
this->result = mysql_query(pSql, this->conn) or die(‘Select false…’);

i = 0;
while (row = mysql_fetch_array(this->result))
{
this->resultArr[i] = row;
i++;
}//while
}//if

return this->resultArr;
}//function readdata();


function navigate()
{
if (this->totalrecords)
{
this->currentpage = (this->beginrecord / this->maxline) + 1;

firstpage = 0;
prevpage = this->beginrecord – this->maxline;
nextpage = this->beginrecord + this->maxline;
lastpage = (this->totalpages – 1)*this->maxline;

if (this->beginrecord == 0)
{
echo ‘[ê×ò3]&nbsp;[é?ò?ò3]&nbsp;’;
}
else
{
echo “<a href=’”._SERVER[\'PHP_SELF\'].”?beginrecord=firstpage’>[ê×ò3]</a>&nbsp;”;
echo “<a href=’”._SERVER[\'PHP_SELF\'].”?beginrecord=prevpage’>[é?ò?ò3]</a>&nbsp;”;
}

if (this->currentpage <= this->maxlist)
{
for (i=1; i<=this->maxlist; i++)
{
pagerecord = (i – 1)*this->maxline;
if (this->currentpage == i)
{
echo “<a href=’”._SERVER[\'PHP_SELF\'].”?beginrecord=pagerecord’>[i]</a>&nbsp;”;
}
else
{
echo “<a href=’”._SERVER[\'PHP_SELF\'].”?beginrecord=pagerecord’>i</a>&nbsp;”;
}//if
}//for
}
elseif (this->currentpage > (this->totalpages-this->maxlist))
{
for (i=(this->maxlist); i>0; i–)
{
pagerecord = (this->totalpages – i)*this->maxline;
if (this->currentpage == (this->totalpages-i+1))
{
echo “<a href=’”._SERVER[\'PHP_SELF\'].”?beginrecord=pagerecord’>[".(this->totalpages - i +1)."]</a>&nbsp;”;
}
else
{
echo “<a href=’”._SERVER[\'PHP_SELF\'].”?beginrecord=pagerecord’>”.(this->totalpages – i+1).”</a>&nbsp;”;
}//if
}//for
}
else
{
j = ceil(this->maxlist / 2);
for (i = j; i>=0; i–)
{
if (this->currentpage == (this->currentpage-i))
{
echo “<a href=’”._SERVER[\'PHP_SELF\'].”?beginrecord=”.((this->currentpage-i-1)*this->maxline).”‘>[".(this->currentpage-i)."]</a>&nbsp;”;
}
else
{
echo “<a href=’”._SERVER[\'PHP_SELF\'].”?beginrecord=”.((this->currentpage-i-1)*this->maxline).”‘>”.(this->currentpage-i).”</a>&nbsp;”;
}
}
for (i = 1; i<=j; i++)
{
echo “<a href=’”._SERVER[\'PHP_SELF\'].’?beginrecord=’.((this->currentpage+i-1)*this->maxline).”‘>”.(this->currentpage+i).”</a>&nbsp;”;
}
}

if (this->beginrecord == lastpage)
{
echo ‘[??ò?ò3]&nbsp;[??ò3]‘;
}
else
{
echo “<a href=’”._SERVER[\'PHP_SELF\'].”?beginrecord=nextpage’>[??ò?ò3]</a>&nbsp;”;
echo “<a href=’”._SERVER[\'PHP_SELF\'].”?beginrecord=lastpage’>[??ò3]</a>”;
}
//echo “this->currentpage / this->totalpages,12óD????êy£othis->totalrecords”;
}
}
}


\n


/*/test
dg = new datagridclass(‘localhost’,\'root’,\'root’,\'test’,2,5);
if (isset(_GET[\'beginrecord\']))
{
dg->__set(‘beginrecord’, _GET[\'beginrecord\']);
}
else
{
dg->__set(‘beginrecord’, 0);
}
rs = dg->readdata(‘select * from testuser’);
if(!rs)
{
echo ‘?Y?Têy?Y?-?-’;
}
else
{
i=0;
echo “<table width=’40%’ border=’1′>”;
echo “<tr><td>id</td><td>name</td></tr>”;
while(i<count(rs))
{
echo “<tr><td>”;
echo rs[i][\'id\'];
echo “</td><td>”.rs[i][\'uname\'];
echo “</td></tr>”;
i++;
}
echo “</tale>”;
}
dg->navigate();
dg = NULL;
*/
?>


\n

à′?′:CSDN

\n