php実現のアリババ模倣同類製品のページめくりを実現

3455 ワード

左側のレコードバー数が$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 <= $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);

/** **/
$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;
        }
        };
        ?>