Home  >  Article  >  Backend Development  >  Alibaba download 2013 free download php imitation Alibaba realizes page turning of similar products

Alibaba download 2013 free download php imitation Alibaba realizes page turning of similar products

WBOY
WBOYOriginal
2016-07-29 08:41:211143browse

If the number of records on the left is less than the value of $space (page number section), the page number $start increases 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 counting by subtracting the $left value from the number of records on the left.

Copy code The code is as follows:


/**Realize page turning 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 = "Previous page

    ";
    }elseif($c == 1) {
    $url = $this->pageName."-".$list1[0]['id'].".html";
    $pages = "< ;a href="{$url}">Previous page
      ";
      }else {
      $pages = "";
      }
      /**Content on the left of the current page **/
      foreach ($list1 as $item) {
      $url = $this->pageName."-".$item['id'].".html";
      $pages .= "
    1. {$start}
    2. ";
      $start++;
      }
      $pages .= "
    3. {$leftCount}< ;/b>
    4. ";
      $start++;
      /**Content on the right side of the current page **/
      foreach($list1 as $item) {
      $url = $this->pageName."-".$ item['id'].".html";
      $pages .= "
    5. {$start}
    6. " ;
      $start++;
      }
      /**Link to next page **/
      $c = count($list2);
      if($c > 0) {
      $url = $this->pageName."-" .$list2[0]['id'].".html";
      $pages .= "Next page
        ";
        }else {
        $pages .= "";
        }
        return $pages;
        }
        };
        ?>

        The above introduces the Alibaba Download 2013 Free Download PHP implementation of imitating Alibaba to realize page turning of similar products, including the content of Alibaba Download 2013 Free Download. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn