Ec (2); php classic paging Class & lt ;? Phpclassdb {public $ conn, $ db, $ table, $ user, $ host, $ unm, $ pwd; public $ res; public $ char; public $ linkType; function _ construct ($ linkTypefalse, $ char & quot; gb2312 & quot;) {& nb script ec (2); script
Php classic Paging
Class db
{
Public $ conn, $ db, $ table, $ user, $ host, $ unm, $ pwd;
Public $ res;
Public $ char;
Public $ linkType;
Function _ construct ($ linkType = false, $ char = "gb2312 ")
{
$ This-> linkType = $ linkType; // you can specify the connection type.
$ This-> char = $ char; // sets the connection verification character.
$ This-> db = DB;
$ This-> user = USER;
$ This-> host = HOST;
$ This-> unm = UNM;
$ This-> pwd = PWD;
If ($ this-> linkType)
{
$ This-> conn = mysql_pconnect ($ this-> host, $ this-> unm, $ this-> pwd) or die ("Database connection failure ");
}
Else
{
$ This-> conn = mysql_connect ($ this-> host, $ this-> unm, $ this-> pwd) or die ("Database connection failure ");
}
Mysql_select_db ($ this-> db );
Mysql_query ("set names". $ this-> char );
}
Function query ($ SQL, $ type = "true ")
{
// $ Type: Default operation. Select Operation
$ This-> res = mysql_query ($ SQL) or die ("SQL Statement error! Please check it again ");
$ Row = $ type? Mysql_num_rows ($ this-> res): mysql_affected_rows ();
$ Result ["res"] = $ this-> res;
$ Result ["row"] = $ row;
Return $ result;
}
// Fetch () method: obtains all records and writes them to an array.
Function fetch ($ SQL)
{
$ Res = self: query ($ SQL );
While ($ rs = mysql_fetch_array ($ res ["res"])
{
$ Result [] = $ rs;
}
Return $ result;
}
// Obtain the next record
Function fetchNext ($ filed, $ currenID, $ table)
{
$ SQL = "select * from $ table where $ filed> $ currenID limit 0, 1 ";
Return self: fetch ($ SQL );
}
// Obtain the previous record
Function fetchPre ($ filed, $ currenID, $ table)
{
$ SQL = "select * from $ table where $ filed <$ currenID limit 0, 1 ";
Return self: fetch ($ SQL );
}
}
Class page extends db
{
Public $ currentPage, $ totalRecord, $ totalPage, $ pageSize;
Public $ start;
Public $ flag;
Public $ SQL;
Function _ construct ($ SQL, $ pagesize = 5, $ flag = "page ")
{
$ This-> SQL = $ SQL;
$ This-> pageSize = $ pagesize;
$ This-> flag = $ flag; // sets the flip link identifier.
$ Row = parent: query ($ SQL );
$ This-> totalRecord = $ row ["row"];
$ This-> totalPage = ceil ($ this-> totalRecord/$ this-> pageSize );
$ Page =$ _ REQUEST [$ this-> flag];
If ($ page <0 | $ page = "")
{
$ This-> currentPage = 1;
}
Else
{
$ Page> $ this-> totalPage? $ This-> currentPage = $ this-> totalPage: $ this-> currentPage = $ page;
}
$ This-> start = ($ this-> currentPage-1) * $ this-> pageSize;
}
// Display the page list
Function show ($ page = 10)
{
$ Str. ='
';
$ Str. ="". $ This-> totalRecord ."";
$ Pre = $ this-> currentPage-1;
If ($ pre! = 0)
{
$ Str. = 'flag. '='. $ pre. 'class = next> <';
}
If ($ this-> currentPage >=$ page)
{
If ($ this-> totalPage-$ this-> currentPage <10)
{
$ Start = $ this-> currentPage-($ this-> currentPage % 10 );
$ End = $ this-> totalPage;
}
Else
{
$ Start = $ this-> currentPage-2;
$ End = $ start + $ page-1;
}
}
Else
{
$ Start = 1;
$ End = 10;
}
For ($ I = $ start; $ I <= $ end; $ I ++)
{
If ($ I ==$ this-> currentPage)
{
$ Str. ="". $ I ."";
}
Else
{
$ Str. = "flag." = $ I> $ I ";
}
}
$ Next = $ this-> currentPage + 1;
$ Str. = 'flag. '='. $ next. 'class = next >>> ';
$ Str. = "flag." = ". $ this-> totalPage." class = last>... ". $ this-> totalPage ."";
$ Str. ="Flag} = '+ this. value; return false ;}\ "/>";
$ Str. ="
";
Return $ str;
}
}
?>
Define ("HOST", "localhost ");
Define ("UNM", "root ");
Define ("PWD", "root ");
Define ("DB", "test ");
Require_once ('db. class. php ');
$ Db = new db ();
$ SQL = "select * from yy ";
$ Page = new page ($ SQL, 10 );
$ SQL. = "limit $ page-> start, $ page-> pageSize ";
$ Rs = $ db-> fetch ($ SQL );
?>
ID |
UNM |
For ($ I = 0; $ I{?>
|
|
}?>
Show ()?> |