PHP翻頁的一個類

來源:互聯網
上載者:User

/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
+------------------------------------------------------------+
| Filename.......: pagenav.php |
| Project........: 大白菜芯 翻 頁 |
| Version........: 2.0.0 |
| Last Modified..: 2003-01-16 |
+------------------------------------------------------------+
| Author.........: wapweb(tyler.wu) <java@cu165.com> |
| Homepage.......: http://tjsohu.com |
| Support........: http://tjsohu.com |
+------------------------------------------------------------+
| Copyright ? 2004 tjsohu.com Team. All rights reserved. |
+------------------------------------------------------------+
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
error_reporting(7);

class buildNav{

var $limit;
var $execute,$query;
var $total_result = 0;
var $offset = "offset";

 

function buildNav($Public,$objClass)
{
$this->Public=$Public;
$this->theClass = $objClass ;
}

function execute($query,$limit){

// global $product;
$GLOBALS[$this->offset] = (!isset($GLOBALS[$this->offset]) OR $GLOBALS[$this->offset]<0) ? 0 : $GLOBALS[$this->offset];
//$this->sql_result = $DB->query($query);

$GLOBALS[$this->offset] = ($GLOBALS[$this->offset]>$this->total_result) ? $this->total_result-10 : $GLOBALS[$this->offset];

if (empty($this->limit)) {
$this->limit = 20;
}else{
$this->limit = $limit;
}

if (isset($this->limit)) {
$query .= " LIMIT " . $GLOBALS[$this->offset] . ", $this->limit";
$this->sql_result = $this->Public->query($query);
$this->num_pages = ceil($this->total_result/$this->limit);
}
if ($GLOBALS[$this->offset]+1 > $this->total_result) {
$GLOBALS[$this->offset] = $this->total_result-1;
}

}

function show_num_pages($frew = "?", $rew = '上一頁', $ffwd = '?', $fwd = '下一頁', $separator = '') {

$current_pg = $GLOBALS[$this->offset]/$this->limit+1;
if ($current_pg > '5') {
$fgp = ($current_pg-5 > 0) ? $current_pg-5 : 1;
$egp = $current_pg+4;
if ($egp > $this->num_pages) {
$egp = $this->num_pages;
$fgp = ($this->num_pages-9 > 0) ? $this->num_pages-9 : 1;
}
} else {
$fgp = 1;
$egp = ($this->num_pages >= 10) ? 10 : $this->num_pages;
}
if($this->num_pages > 1) {
// searching for http_get_vars
foreach ($GLOBALS[HTTP_GET_VARS] as $_get_name => $_get_value) {
if ($_get_name != $this->offset) {
$this->_get_vars .= "&$_get_name=$_get_value";
}
}
$this->listNext = $GLOBALS[$this->offset] + $this->limit;
$this->listPrev = $GLOBALS[$this->offset] - $this->limit;
// $this->theClass = $objClass;
if (!empty($rew)) { //$separator [$frew] $rew
$return .= ($GLOBALS[$this->offset] > 0) ? "offset=0$this->_get_vars/" $this->theClass title=/"第一頁/">$frew offset=$this->listPrev$this->_get_vars/" $this->theClass title=/"上一頁/">$rew $separator " : "";
}

// showing pages
if ($this->show_pages_number || !isset($this->show_pages_number)) {
for($this->a = $fgp; $this->a <= $egp; $this->a++) {
$this->theNext = ($this->a-1)*$this->limit;
if ($this->theNext != $GLOBALS[$this->offset]) {
$return .= " offset=$this->theNext$this->_get_vars/" $this->theClass> ";
if ($this->number_type == 'alpha') {
$return .= chr(64 + ($this->a));
} else {
$return .= $this->a;
}
$return .= " ";
} else {
if ($this->number_type == 'alpha') {
$return .= chr(64 + ($this->a));
} else {
$return .= "$this->a";
}
$return .= ($this->a < $this->num_pages) ? " $separator " : "";
}
}
$this->theNext = $GLOBALS[$this->offset] + $this->limit;
if (!empty($fwd)) {
$offset_end = ($this->num_pages-1)*$this->limit; //$separator $fwd [$ffwd]
$return .= ($GLOBALS[$this->offset] + $this->limit < $this->total_result) ? "$separator offset=$this->listNext$this->_get_vars/" $this->theClass title=/"下一頁/">$fwd offset=$offset_end$this->_get_vars/" $this->theClass title=/"最後一頁/">$ffwd" : "";
}
}
}
return $return;
}

// [Function : Showing the Information for the Offset]
function show_info() {

$return .= "共: ".$this->total_result." , ";
$list_from = ($GLOBALS[$this->offset]+1 > $this->total_result) ? $this->total_result : $GLOBALS[$this->offset]+1;
$list_to = ($GLOBALS[$this->offset]+$this->limit >= $this->total_result) ? $this->total_result : $GLOBALS[$this->offset]+$this->limit;
//$return .= 'Showing Results from ' . $list_from . ' - ' . $list_to . '
';
$return .= "顯示: ".$list_from ." - ".$list_to;
return $return;
}

/*因為現在的這個編輯器不能正常解釋我西邊的代碼,我就抓了圖來完成真箇函數。如果您需要請按照下邊的輸入就可以了*/

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.