- 論壇徽章:
- 0
|
提供完全可以使用的類,使用時(shí)請(qǐng)初始化各函數(shù)!
dbClass();
$this->maxLine = $pageLine;
}
// 記錄總數(shù)
function getTotal(){
return $this->Total;
}
// 顯示總頁(yè)數(shù)
function getTotalPages() {
return $this->TPages;
}
//顯示當(dāng)前所在頁(yè)數(shù)
function getCurrenPages() {
return $this->CPages;
}
function myQuery($sql, $flag=1){
GLOBAL $offset;
$this->Query = $sql;
// 獲取文件名
//$this->FilePath = $GLOBALS["REQUEST_URI"];
$this->FilePath = $GLOBALS["SCRIPT_NAME"];
// 獲取查詢條件
$this->QueryString = $GLOBALS["QUERY_STRING"];
//echo $this->QueryString . "
";
// 截取 " from " 以后的 query 語(yǔ)句
$this->QueryPart = trim(strstr($sql, " from "));
// 計(jì)算偏移量
if (!isset($offset)) $this->Offset = 0;
else $this->Offset = (int)$offset;
// 計(jì)算總的記錄條數(shù)
$SQL = "SELECT Count(*) AS total " . $this->QueryPart;
$this->result = $this->executeQuery($SQL);
$this->Total = mysql_result($this->result,0);
// 設(shè)置當(dāng)前頁(yè)數(shù)和總頁(yè)數(shù)
$this->TPages = (double)Ceil((double)$this->Total/$this->maxLine);
$this->CPages = (double)Floor((double)$this->Offset/$this->maxLine+1);
// 根據(jù)條件判斷,取出所需記錄
if ($this->Total > 0) {
//flag等于1表示要分頁(yè),否則不分頁(yè)
if($flag==1)
$SQL = $this->Query . " LIMIT " . $this->Offset . " , " . $this->maxLine;
else
$SQL = $this->Query;
echo $SQL . "
";
$this->$result = $this->executeQuery($SQL);
}
return $this->result;
}
//**********顯示翻頁(yè)提示欄*************
// 顯示首頁(yè)、下頁(yè)、上頁(yè)、尾頁(yè)
function PageLegend() {
$str = "";
$i = 0;
$first = 0;
$next = 0;
$prev = 0;
$last = 0;
$next = $this->Offset + $this->maxLine;
$prev = $this->Offset - $this->maxLine;
$last = ($this->TPages - 1) * $this->maxLine;
GLOBAL $offset;
if (!isset($offset)) $this->QueryString .= "&offset=";
else{
$this->QueryString = substr($this->QueryString,0,strrpos($this->QueryString,'&')) . "&offset=";
}
if($this->Offset >= $this->maxLine)
$str .= " FilePath . "?" . $this->QueryString . $first . ">首頁(yè) ";
else $str .= " 首頁(yè) ";
if($prev >= 0)
$str .= " FilePath . "?" . $this->QueryString . $prev . ">前頁(yè) ";
else $str .= " 前頁(yè) ";
if($next Total)
$str .= " FilePath . "?" . $this->QueryString . $next . ">后頁(yè) ";
else $str .= " 后頁(yè) ";
if($this->TPages != 0 && $this->CPages TPages)
$str .= " FilePath . "?" . $this->QueryString . $last . ">尾頁(yè)";
else $str .= " 尾頁(yè) ";
$str .= " 頁(yè)次:" . $this->getCurrenPages() . "/" . $this->getTotalPages() . "頁(yè) ";
$str .= $this->maxLine . "條/頁(yè) " . "共" . $this->Total . "條";
return $str;
}
}
?>
本文來(lái)自ChinaUnix博客,如果查看原文請(qǐng)點(diǎn):http://blog.chinaunix.net/u/3052/showart_8770.html |
|