If the number of records on the left is less than the value of $ space (page number segment), the value of page number $ start is increased from 1 to the right. If the number of records on the left is more than the value of $ left (the number of pages displayed on the left and right), $ start will start from the number of records on the left minus the value of $ left.
CopyCode The Code is as follows: <? PHP
/** Turn pages of similar products **/
Class Pager
{
Protected $ space;
Protected $ left;
Protected $ dB;
Protected $ pagename;
Public Function setspace ($ num ){
$ This-> Space = $ num;
$ This-> left = Ceil ($ num-1)/2 );
}
Public Function setdb (& $ dB ){
$ This-> DB = $ dB;
}
Public Function setpagename ($ pagename ){
$ This-> pagename = $ pagename;
}
Public Function getpages ($ catid, $ exptime ){
$ Fields = array ("'id', 'title '");
$ Left = array (">" => array ("exptime" => $ exptime), "memberid" => Gs (_ mem_prefix _. "memberid"), "catid" => $ catid );
$ Right = array ("<" => array ("exptime" => $ exptime), "memberid" => Gs (_ mem_prefix _. "memberid"), "catid" => $ catid );
$ Leftcount = $ this-> DB-> getcount ($ left );
If ($ leftcount <= $ this-> left ){
$ Star = 1;
$ Leftlimit = "limit". $ leftcount;
$ Rightlimit = "limit". ($ this-> space-$ leftcount );
}
Else {
$ Start = $ leftcount-$ this-> left;
$ Leftlimit = "limit". $ this-> left;
$ Rightlimit = $ leftlimit;
}
$ List1 = $ this-> DB-> findall ($ left, array ("exptime" => "ASC"), $ leftlimit, $ fields );
$ List2 = $ this-> DB-> findall ($ right, array ("exptime" => "DESC"), $ rightlimit, $ fields );
/** Previous Page Link **/
$ C = count ($ list1 );
If ($ C> 1 ){
$ Url = $ this-> pagename. "-". $ list1 [$ C] ['id']. ". html ";
$ Pages = "<a href = \" {$ URL} \ "> previous page </a> <ol> ";
} Elseif ($ c = 1 ){
$ Url = $ this-> pagename. "-". $ list1 [0] ['id']. ". html ";
$ Pages = "<a href = \" {$ URL} \ "> previous page </a> <ol> ";
} Else {
$ Pages = "";
}
/** Content on the left of the current page **/
Foreach ($ list1 as $ item ){
$ Url = $ this-> pagename. "-". $ item ['id']. ". html ";
$ Pages. = "<li> <a href = \" {$ URL} \ ">{$ start} </a> </LI> ";
$ Start ++;
}
$ Pages. = "<li> <B >{$ leftcount} </B> </LI> ";
$ Start ++;
/** Content on the right of the current page **/
Foreach ($ list1 as $ item ){
$ Url = $ this-> pagename. "-". $ item ['id']. ". html ";
$ Pages. = "<li> <a href = \" {$ URL} \ ">{$ start} </a> </LI> ";
$ Start ++;
}
/** Next page Link **/
$ C = count ($ list2 );
If ($ C> 0 ){
$ Url = $ this-> pagename. "-". $ list2 [0] ['id']. ". html ";
$ Pages. = "<a href = \" {$ URL} \ "> next page </a> <ol> ";
} Else {
$ Pages. = "";
}
Return $ pages;
}
};
?>