PHP paging Library
Last Update:2017-05-14
Source: Internet
Author: User
PHP paging Library Class PageBar
{
Var $ total;
Var $ onepage;
Var $ num;
Var $ pageID;
Var $ total_page;
Var $ linkhead;
Function PageBar ($ total, $ onepage)
{
$ PageID = $ _ GET ['pageid'];
$ This-> total = $ total;
$ This-> onepage = $ onepage;
$ This-> total_page = @ ceil ($ total/$ onepage );
If (empty ($ pageID ))
{
$ This-> pageID = 1;
$ This-> offset = 0;
}
Else
{
$ This-> pageID = $ pageID;
$ This-> offset = ($ pageID-1) * $ onepage;
}
$ Linkarr = explode ("& pageID =", $ _ SERVER ['query_string ']);
$ Linkft = $ linkarr [0];
$ Self = str_replace ("index. php", "", $ _ SERVER ['php_self ']);
If (empty ($ linkft ))
$ This-> linkhead = $ self ."? ". $ Formlink;
Else
$ This-> linkhead = $ self ."? ". $ Linkft. $ formlink;
}
Function pre_page ($ char = '', $ others = '')
{
$ Linkhead = $ this-> linkhead;
$ PageID = $ this-> pageID;
If ($ pageID> 1)
{
$ Pre_page = $ pageID-1;
If ($ others)
Return "$ char ";
Else
Return "$ char ";
}
Else
Return '';
}
Function next_page ($ char = '', $ others = '')
{
$ Linkhead = $ this-> linkhead;
$ Total_page = $ this-> total_page;
$ PageID = $ this-> pageID;
If ($ pageID <$ total_page)
{
$ Next_page = $ pageID + 1;
If ($ others)
Return "$ char ";
Else
Return "$ char ";
}
Else
Return '';
}
Function num_bar ($ num = '', $ color ='', $ others = '', $ left ='', $ right = '')
{
$ Num = (empty ($ num ))? 10: $ num;
$ This-> num = $ num;
$ Mid = floor ($ num/2 );
$ Last = $ num-1;
$ PageID = $ this-> pageID;
$ Totalpage = $ this-> total_page;
$ Linkhead = $ this-> linkhead;
$ Left = (empty ($ left ))? "[": $ Left;
$ Right = (empty ($ right ))? "]": $ Right;
$ Color = (empty ($ color ))? "# Ff0000": $ color;
$ Minpage = ($ pageID-$ mid) <1 )? 1: ($ pageID-$ mid );
$ Maxpage = $ minpage + $ last;
If ($ maxpage> $ totalpage)
{
$ Maxpage = $ totalpage;
$ Minpage = $ maxpage-$ last;
$ Minpage = ($ minpage <1 )? 1: $ minpage;
}
For ($ I = $ minpage; $ I <= $ maxpage; $ I ++)
{
$ Char = $ left. $ I. $ right;
If ($ I = $ pageID)
$ Linkchar = "$ char ";
Else
$ Others? $ Linkchar = "". $ char. "": $ linkchar = "". $ char ."";
$ Linkbar = $ linkbar. $ linkchar;
}
Return $ linkbar;
}
Function pre_group ($ char = '', $ others = '')
{
$ PageID = $ this-> pageID;
$ Linkhead = $ this-> linkhead;
$ Num = $ this-> num;
$ Mid = floor ($ num/2 );
$ Minpage = ($ pageID-$ mid) <1 )? 1: ($ pageID-$ mid );
$ PgpageID = ($ minpage> $ num )? $ Minpage-$ mid: 1;
If ($ pageID! = $ Minpage)
$ Others? $ LinkHerf = "". $ char. "": $ linkHerf = "". $ char ."";
Else
$ LinkHerf = $ char;
Return $ linkHerf;
}
Function next_group ($ char = '', $ others = '')
{
$ PageID = $ this-> pageID;
$ Linkhead = $ this-> linkhead;
$ Totalpage = $ this-> total_page;
$ Num = $ this-> num;
$ Mid = floor ($ num/2 );
$ Last = $ num;
$ Minpage = ($ pageID-$ mid) <1 )? 1: ($ pageID-$ mid );
$ Maxpage = $ minpage + $ last;
If ($ maxpage> $ totalpage)
{
$ Maxpage = $ totalpage;
$ Minpage = $ maxpage-$ last;
$ Minpage = ($ minpage <1 )? 1: $ minpage;
}
$ NgpageID = ($ totalpage> $ maxpage + $ last )? $ Maxpage + $ mid: $ totalpage;
If ($ pageID = $ maxpage | $ maxpage = 0)
$ LinkHerf = $ char;
Else
$ Others? $ LinkHerf = "". $ char. "": $ linkHerf = "". $ char ."";
Return $ linkHerf;
}
Function whole_num_bar ($ num = '', $ color ='', $ others = '')
{
$ Num_bar = $ this-> num_bar ($ num, $ color, $ others );
$ Pre_group = $ this-> pre_group ('| <', $ others );
$ Pre_page = $ this-> pre_page ('<', $ others );
$ Next_page = $ this-> next_page ('>', $ others );
$ Next_group = $ this-> next_group ('> |', $ others );
Return $ pre_group. $ pre_page. $ num_bar. $ next_page. $ next_group;
}
}
?>