CodeIgniter Forums
Pagination - show number results on current page - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Pagination - show number results on current page (/showthread.php?tid=81212)

Pages: 1 2


Pagination - show number results on current page - sjender - 02-04-2022

Hi,
I am using the pagination library to create some overviews.
On these pages, I would like to show how many results there are on the current page.
For example:
Users: 15 of 25
I can use $pager->getTotal for the total amount, but there doesn't seem to be a method to show the number of results on the current page.
Am I missing something???
I'm sure I'm not the only one who needs this.


RE: Pagination - show number results on current page - kenjis - 02-04-2022

See https://codeigniter4.github.io/userguide/libraries/pagination.html#creating-the-view
getPageCount()


RE: Pagination - show number results on current page - sjender - 02-05-2022

This method returns total number of pages.

I need the number of results on the current page.


RE: Pagination - show number results on current page - iRedds - 02-05-2022

count($rows) ?


RE: Pagination - show number results on current page - kenjis - 02-05-2022

(02-05-2022, 05:07 AM)sjender Wrote: This method returns total number of pages.

I need the number of results on the current page.

What do you mean?
getCurrentPageNumber() ?


RE: Pagination - show number results on current page - wdeda - 02-05-2022

I believe he is wanting something like:
"Showing 1 to 10 of xx results" on each page shown.
The best example for this is DataTables, I suppose.


RE: Pagination - show number results on current page - sjender - 02-05-2022

Yes. That's what I mean.
But there doesn't seem to be a method for that.
Surely I can work my way around it. But it would be nice if there was a method within $pager for that.


RE: Pagination - show number results on current page - InsiteFX - 02-06-2022

Ok guy's this is how I' am doing it in my new blog I' am working on.

PHP Code:
<!-- Pagination Views/pagination.php include this view in your view or layout. -->
<
div class="pagination justify-content-center mb-4">
    <?php if ( ! empty($pager)) :
        //echo $pager->simpleLinks('group1', 'bs_simple');
        echo $pager->links('group1''bs_full');
    endif ?>

    <!-- Bootstrap 5.1.3 code to show page 1 of 4 total pages using a button. -->
    <div class="btn-group pagination justify-content-center mb-4" role="group" aria-label="pager counts">
        &nbsp;&nbsp;&nbsp;
        <!-- NOTE: $currentPage and $totalPages are set in the Controllers $data and passed in to the view. -->
        <button type="button" class="btn btn-light"><?= 'Page '.$currentPage.' of '.$totalPages?></button>
    </div>
</div> <!-- End of pagination -->

// Controller
$data = [
    'pager'      => $posts->pager,
    'currentPage' => $posts->pager->getCurrentPage('group1'),
    'totalPages'  => $posts->pager->getPageCount('group1'),
]; 

Make sure you read the comments in the code.


RE: Pagination - show number results on current page - sjender - 02-07-2022

It looks like I am not explaining my issue very well Smile.

I will explain it in more detail (because the example InsiteFX has provided, shows the number of pages, that's not what I mean).

Imagine making an overview of al registered users of the site.
In this example there are 55 users.

I will use the paginator service and I set the number of results per page on 20....

So, the first page wil have 20 users on it.
The second also 20
But the third only 15.

In the topbar of the table I want to show this number (users on this specific page).

So.......

Page 1 should have "Users: showing 20 of 55"
Page 2 should have "Users: showing 20 of 55"
Page 3 should have "Users: showing 15 of 55"

The total amount (55) is not a problem, that is $pager->getTotal().
But the first one (20, 20, 15) is the one I'm looking for..

I hope I have made my issue somewhat more understandable like this?


RE: Pagination - show number results on current page - InsiteFX - 02-07-2022

That's some thing your going to have to write yourself, there are no method's for that.

Maybe create a helper for it.