Back to Top

How To use Pagination in Joomla

To use Pagination in Joomla

Before some days, I was worked on one site and In this I need to add pagination on some pages in which only some contents were displaying at a what I have done to add pagination in those pages in Joomla, want to share with you so you get some idea to use default Joomla pagination.

First of all, I have taken one variable $limit and define My Per page limit in it.

$limit = 10;

After then I have to create offset for start limit

$offset = JRequest::getVar('limitstart', 0, '', 'int');

Let me explain about getVar function, the getVar function is used to GET data from the request uri.


getVar(Uri_field,Default_value, Value_type,Variable_type);

Uri_field: The field name you get value in it. i.e, index.php?limitstart = 0

Default_value: Default value that will be returned if the query name is not exist.

Value_type: HTTP request type(get or post or request) By deafult,its GET.

Variable_type: Data Type of the variable.

Next, I have written a database query to get number of rows and to retrieve all records

$database->setQuery('SELECT SQL_CALC_FOUND_ROWS book_id, title, image, created FROM #__books WHERE deleted=0 AND published=1,$offset, $limit);	
$resultSet =$database->loadObjectList();

Basically, To get Pagination in you need to execute query two times.The first query is to count a total number of rows without LIMIT. The second query is exactly the same as the first, just without LIMIT and it will actually retrieve required data. It’s difficult to use two query when you have the complex query that joins several tables.if you don’t want to execute complex query twice and don’t want to waste server resources, you can use SQL_CALC_FOUND_ROWS option of MySQL

SQL_CALC_FOUND_ROWS is a one feature of the MySql used to count total number of rows disregarding LIMIT clause in the SELECT statement

and Now, FOUND_ROWS() returns the total number of rows in the result set returned by that statement.

Note: SQL_CALC_FOUND_ROWS and FOUND_ROWS statements are much faster

Next, SQL queries to get total rows

if (!empty($resultSet))
	$database->setQuery('SELECT FOUND_ROWS();'); // To get Total records without reloading whole query
	jimport('joomla.html.pagination'); // import pagination class
	$pageNav = new JPagination( $database->loadResult(), $offset, $limit );

JPagination is the core class of Joomla used to add pagination to the Front-end and Back-end.JPagination has three parameters, first is the total records, the second is offset(or start limit) and the third parameter is rows per page.

$content = $pageNav->getListFooter(); //Display Limit dropdown, the Pages Links and the Pages Counter
foreach ($resultSet as $row) {
	// To display retrieved data

Suggested Reading:

About Module Position in Joomla
Free shipping for specific Country in Virtuemart Joomla
Custom Query with Joomla

Hope above contents has helped you to use default Joomla pagination in your site.

Comments (7)

  1. Nice 1 publish.

  2. Please post an example script.


  3. Thanks Works fine Saves my effort

  4. An outstanding share!I have just forwarded thhis onto a friend whho was doing a little homework on this.
    And he in fact bought me lunch simly because I found
    it for him… lol. So let me reword this…. Thank YOU for the meal!!
    But yeah, thanks for spending some time to talpk about this topic
    here on your wweb site.

  5. this one is nice
    but i want to use multiple pagination in same view so please reply me how to use it

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

How does CI/CD works on AWS?

Posted on 2 years ago


How to create Custom regions in Drupal

Posted on 6 years ago


How to use HTML5 Page Visibility API

Posted on 3 years ago


To prevent caching in web browser

Posted on 7 years ago


Hello world

Updated 5 days ago

Nick Carter

In depth Understanding of Laravel Core

Updated 2 months ago


ECMAScript 6 New Features – 2

Updated 1 year ago


The Reader’s Poll – June 2015

Posted on 4 years ago


The Reader’s Poll – August 2014

Posted on 4 years ago


The Reader’s Poll – June 2014

Posted on 5 years ago


The Readers’ Poll – May 2014

Posted on 5 years ago


The Readers’ Poll – August 2013

Posted on 5 years ago