小規模データベース向き
$sql = 'SELECT * FROM table'; $itemData = $mdb2->queryAll($sql); require_once('Pager.php'); $extraVars = array( 'F' => 'function' , 'A' => 'action' ); $params = array( 'perPage' => 5 , 'itemData' => $itemData , 'importQuery' => FALSE , 'extraVars' => $extraVars ); $pager = Pager::factory($params); $data = $pager->getPageData(); $links = $pager->getLinks();
大規模データベース向き
$sql = 'SELECT * FROM table'; $res = $mdb2->query($sql); $total = $res->numRows(); require_once('Pager.php'); $extraVars = array( 'F' => 'function' , 'A' => 'action' ); $params = array( 'perPage' => 5 , 'totalItems' => $total , 'importQuery' => FALSE , 'extraVars' => $extraVars ); $pager = Pager::factory($params); list($from, $to) = $pager->getOffsetByPageId(); $links = $pager->getLinks(); $mdb2->setLimit($params['perPage'], $from - 1); $data = $mdb2->queryAll($sql);
全データ数
$total = $pager->numItems();
現在のページ
$current = $pager->getCurrentPageID();
全ページ数
$all = $pager->numPages();