0
votes

I am using following code for pagination

I am limit the database result fetching by 10,

        $result = $model->search(); // sql Limit 10
        $paginator = Zend_Paginator::factory($result['listings']);
        $paginator->setItemCountPerPage(10);
        $paginator->setCurrentPageNumber($page);
        $this->view->paginator = $paginator;

I have about 10,000 records in database and I am trying to fetch 10 results for each database request and show.

But here for Pagination, we need to fetch all the results and need to pass to Zend Paginator, which causes a performance issue. So how I fetch only 10 results per page using SQL offset and limit like 1,10... 11,10...21,10

On clicking 2nd page I need to fetch result from database with offset and limit as 11,10 and so on

I need to fetch each page result dynamically from database. How is it possible??

1

1 Answers

0
votes

Yes, i also found this issue...i was thinking of the same case last week. Can you try

my pagination URL: http://zf2.localhost/controller/?page=2

$SetItemCount=10;
$CurrentPage=$this->params()->fromQuery('page');
$NextPage=$current_page+1;
$result = $model->search($NextPage,$SetItemCount);
$paginator = Zend_Paginator::factory($result['listings']);
$paginator->setItemCountPerPage($SetItemCount);
$paginator->setCurrentPageNumber($page);
$this->view->paginator = $paginator;

I haven't personally tried this. i was thinking to proceed like this. You many need to buffer the result set and use Iterator also.