快速分頁 - Pager

edited 十月 2013 in PEAR&PECL
網址: http://pear.php.net/package/Pager

It takes an array of data as input and pages it according to various parameters.
It also builds links within a specified range, and allows complete customization of the output (it even works with front controllers and mod_rewrite).
Two operating modes available: "Jumping" and "Sliding" window style.

它能夠以一個陣列作為輸入,然後根據各種參數進行分頁;也能夠在指定的範圍內建立連結,輸出的資料也能夠作完整的客製化(甚至能夠運行在前段控制物件與 mod_rewrite 環境中)。允許使用兩種模式: "跳躍" 與 "滑動" 視窗風格。

我作一個簡單的資料庫存取範例:
    require_once 'Pager/Pager.php';
    $sql1 = 'SELECT `id` FROM `mydata`'; 
    $total = mysql_num_rows(mysql_query($sql1)); //取得資料總數
    $params = array(
        'mode'       => 'Sliding',
        'perPage'    => 20,
        'totalItems' => $total,
        'delta'      => 4,
        'urlVar'     => 'page',
    );
    $pager = & Pager::factory($params);
    $offset = $pager->getOffsetByPageId($pager->getCurrentPageID());
    $offset[0] -= 1;
    $sql2 = 'SELECT * FROM `mydata` LIMIT '.$offset[0].', '.$pager->_perPage;
    echo $pager->links; // 這樣子就會產生分頁所需要的連結,點選後的參數也會帶入資料庫查詢中,很快吧 :)

原始討論: http://twpug.net/x/modules/newbb/viewtopic.php?topic_id=1214
Sign In or Register to comment.