3

我想为大量数据集设置分页,比如数万。如果一次获取所有数据,性能会很慢。所以我需要一个更好的方法:

在我的控制器中,我有给定的代码:

    $result = $result = $this->fetchAll($this->select()
                                            ->where('id='.$id)
                                            ->order('date DESC'))->toArray();
    $paginator = Zend_Paginator::factory($data);
    $pageNumber = $this->_getParam('page');       
    $paginator->setCurrentPageNumber($pageNumber);
    $paginator->setItemCountPerPage(10);
    $this->view->data = $paginator;

此代码将一次获取所有数据库内容。

4

2 回答 2

1

尝试这个

    $select = $this->select()->where('id='.$id)
                             ->order('date DESC');

    $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($select));
    $pageNumber = $this->_getParam('page');       
    $paginator->setCurrentPageNumber($pageNumber);
    $paginator->setItemCountPerPage(10);
    $this->view->data = $paginator; 
于 2013-05-17T11:20:25.343 回答
0

尝试这个:

$select = new Zend_Paginator_Adapter_DbSelect($sql);
$select->count($select);
$paginator = new Zend_Paginator($select);

您可以从这里获得更多详细信息:

分页数据收集

于 2013-05-17T11:31:22.650 回答