PHP achieves similar product pages through Alibaba

Source: Internet
Author: User

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;
}
};
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.