If the number of record bars on the left is less than the $space (page segment) value, the page number $start from 1 to the right. If the number of record bars on the left is more than $left (the left and right pages are displayed), $start the number of records from the left record minus the $left value.
Copy Code code as follows:
<?php
/** to achieve the same product 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" => $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;
}
$list 1 = $this->db->findall ($left, Array ("Exptime" => "ASC"), $leftLimit, $fields);
$list 2 = $this->db->findall ($right, Array ("Exptime" => "DESC"), $rightLimit, $fields);
/** previous page link **/
$c = count ($list 1);
if ($c > 1) {
$url = $this->pagename. " -". $list 1[$c] [' ID '].". HTML ";
$pages = "<a href=\" {$url}\ > prev </a><ol>;
}elseif ($c = = 1) {
$url = $this->pagename. " -". $list 1[0][' id '].". HTML ";
$pages = "<a href=\" {$url}\ > prev </a><ol>;
}else {
$pages = "";
}
/** the left content of the current page **/
foreach ($list 1 as $item) {
$url = $this->pagename. " -". $item [' id '].". HTML ";
$pages. = "<li><a href=\" {$url}\ ">{$start}</a></li>";
$start + +;
}
$pages. = "<li><b>{$leftCount}</b></li>";
$start + +;
/** the content on the right side of the current page **/
foreach ($list 1 as $item) {
$url = $this->pagename. " -". $item [' id '].". HTML ";
$pages. = "<li><a href=\" {$url}\ ">{$start}</a></li>";
$start + +;
}
/** the next page of the link **/
$c = count ($list 2);
if ($c > 0) {
$url = $this->pagename. " -". $list 2[0][' id '].". HTML ";
$pages. = "<a href=\" {$url}\ "> Next </a><ol>";
}else {
$pages. = "";
}
return $pages;
}
};
?>