如果左邊的記錄條數小於$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 = "上一頁
以上就介紹了阿里巴巴下載2013免費下載 php實現的仿阿里巴巴實現同類產品翻頁,包括了阿里巴巴下載2013免費下載方面的內容,希望對PHP教程有興趣的朋友有所幫助。