Heim >Backend-Entwicklung >PHP-Tutorial >阿里巴巴下载2013免费下载 php实现的仿阿里巴巴实现同类产品翻页

阿里巴巴下载2013免费下载 php实现的仿阿里巴巴实现同类产品翻页

WBOY
WBOYOriginal
2016-07-29 08:41:211161Durchsuche

如果左边的记录条数小于$space(页码区段)的值,页码$start从1开始向右增值。如果左则的记录条数多于$left(左右各显示页数)的值,$start将从左边记录数减去$left值开始记数。

复制代码 代码如下:


/** 实现同类产品翻页 **/
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 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);
/** 上一页链接 **/
$c = count($list1);
if($c > 1) {
$url = $this->pageName."-".$list1[$c]['id'].".html";
$pages = "上一页

    ";
    }elseif($c == 1) {
    $url = $this->pageName."-".$list1[0]['id'].".html";
    $pages = "上一页
      ";
      }else {
      $pages = "";
      }
      /** 当前页的左边内容 **/
      foreach($list1 as $item) {
      $url = $this->pageName."-".$item['id'].".html";
      $pages .= "
    1. {$start}
    2. ";
      $start++;
      }
      $pages .= "
    3. {$leftCount}
    4. ";
      $start++;
      /** 当前页面右边的内容 **/
      foreach($list1 as $item) {
      $url = $this->pageName."-".$item['id'].".html";
      $pages .= "
    5. {$start}
    6. ";
      $start++;
      }
      /** 下一页的链接 **/
      $c = count($list2);
      if($c > 0) {
      $url = $this->pageName."-".$list2[0]['id'].".html";
      $pages .= "下一页
        ";
        }else {
        $pages .= "";
        }
        return $pages;
        }
        };
        ?>

        以上就介绍了阿里巴巴下载2013免费下载 php实现的仿阿里巴巴实现同类产品翻页,包括了阿里巴巴下载2013免费下载方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn