If the number of record bars on the left is less than the value of $space (page segment), the page number $start increment from 1 to the right. If the number of records on the left is greater than the value of $left (the left and right pages), $start will start counting from the left record minus the $left value.
Copy CodeThe code is as follows:
/** realization of similar products page **/
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" and "= $catid);
$right = Array ("<" = = Array ("exptime" = = $exptime), "MemberID" = GS (_mem_prefix_. "MemberID"), "catid" and "= $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;
}
$list 1 = $this->db->findall ($left, Array ("exptime" = "ASC"), $leftLimit, $fields);
$list 2 = $this->db->findall ($right, Array ("exptime" = "DESC"), $rightLimit, $fields);
/** prev Link **/
$c = count ($list 1);
if ($c > 1) {
$url = $this->pagename. " -". $list 1[$c [' id '].". HTML ";
$pages = "Previous page
";
}elseif ($c = = 1) {
$url = $this->pagename. " -". $list 1[0][' id '].". HTML ";
$pages = "Previous page
";
}else {
$pages = "";
}
/** the left content of the current page **/
foreach ($list 1 as $item) {
$url = $this->pagename. " -". $item [' id '].". HTML ";
$pages. = "
- {$start}
";
$start + +;
}
$pages. = "
- {$leftCount}
";
$start + +;
/** content to the right of the current page **/
foreach ($list 1 as $item) {
$url = $this->pagename. " -". $item [' id '].". HTML ";
$pages. = "
- {$start}
";
$start + +;
}
/** link to next page **/
$c = count ($list 2);
if ($c > 0) {
$url = $this->pagename. " -". $list 2[0][' id '].". HTML ";
$pages. = "Next page
";
}else {
$pages. = "";
}
return $pages;
}
};
?>
http://www.bkjia.com/phpjc/320934.html www.bkjia.com True http://www.bkjia.com/phpjc/320934.html techarticle If the left number of record bars is less than $space ( Page number section), the page number $start from 1 to the right value. If the number of records on the left is greater than the value of $left (the left and right pages), $start will be from left ...
-