Go homepage(回首页)
Upload pictures (上传图片)
Write articles (发文字帖)

The author:(作者)归海一刀
published in(发表于) 2014/2/17 7:30:01
PHP实例-PHP分页代码_[PHP教程]

PHP实例:PHP分页代码_[PHP教程]

/*
* 文件名:datagridclass.php
* 作者:感染源
* 时间:2007-07-25
* 描述:分页类
*/
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 '[首页] [上一页] ';
}
else
{
echo "[首页] ";
echo "[上一页] ";
}

if (this->currentpage <= this->maxlist)
{
for (i=1; i<=this->maxlist; i++)
{
pagerecord = (i - 1)*this->maxline;
if (this->currentpage == i)
{
echo "[i]&nbsp;";
}
else
{
echo "i&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 "[".(this->totalpages - i +1)."]&nbsp;";
}
else
{
echo "".(this->totalpages - i+1)."&nbsp;";
}//if
}//for
}
else
{
j = ceil(this->maxlist / 2);
for (i = j; i>=0; i--)
{
if (this->currentpage == (this->currentpage-i))
{
echo "[".(this->currentpage-i)."]&nbsp;";
}
else
{
echo "".(this->currentpage-i)."&nbsp;";
}
}
for (i = 1; i<=j; i++)
{
echo "".(this->currentpage+i)."&nbsp;";
}
}

if (this->beginrecord == lastpage)
{
echo '[下一页]&nbsp;[末页]';
}
else
{
echo "[下一页]&nbsp;";
echo "[末页]";
}
//echo "this->currentpage / this->totalpages,共有记录数:this->totalrecords";
}
}
}



/*/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 '暂无数据……';
}
else
{
i=0;
echo "";
echo "idname";
while(i {
echo "";
echo rs[i]['id'];
echo "".rs[i]['uname'];
echo "";
i++;
}
echo "";
}
dg->navigate();
dg = NULL;
*/
?>


来源:CSDN







If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)





QQ:154298438
QQ:417480759