Home > Article > Backend Development > Alibaba download 2013 free download php imitation Alibaba realizes page turning of similar products
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
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.