adding (Showing current start to number of entries of Total entries) in zend Paginator

78 Views Asked by At

what i want to do is that i wana show user this

Showing 1 to  10 of 50 entries
Showing 11 to 20 of 50 entries
Showing 21 to 30 of 50 entries
Showing 31 to 40 of 50 entries
Showing 41 to 50 of 50 entries

i have used Zend Paginator in my app lets say

 Showing A to B of C entries

I can easily find C which is equal to

 $result = $DB->fetchAll($sql);
 $total =count($result); 

if we see here

 $page=$this->_getParam('page',1);
 //here we can get the requested page#.
 //lets hard code this
  $paginator->setItemCountPerPage(10);
  $per_page =10; 
  in my view   count($this->paginator)   give me total number of pages that is if
  if        total = 101     = $total
  than      page = 9        = $page
 and        paginator = 11  = count($this->paginator)

how can i achieve this but generic mean working with next,previous and so on..

1

There are 1 best solutions below

0
On BEST ANSWER

Showing A to B of C entries

Is roughly this:

$page = $paginator->getCurrentPageNumber();
$perPage = $paginator->getItemCountPerPage();
$total = $paginator->getTotalItemCount();

$A = ($page - 1) * $perPage + 1;
$B = min($A + $perPage - 1, $total);
$C = $total;