Home » PEAR, Smarty20 July 2008

Pagination in PEAR and Smarty

First of all, you need to install PEAR in your web server. Then you need to install Smarty.

After that, you need to install a package in PEAR. It’s called ‘Pager’.

Pager is a class to page an array of data. It is taken as input and it is paged according to various parameters. Pager also builds links within a specified range, and allows complete customization of the output.

In the index.php file, we make a function named getPager(). This function contains four parameters – $item, $perPage, $mode, and $delta.

$item is the array of data.
$perPage is the number of data to be displayed per page.
$mode defines about the mode of pagination links. There are two types of modes – Sliding and Jumping. The Jumping mode displays ‘Back’ and ‘Next’ link.
$delta defines the width of pagination links. High value of $delta increases the width of pagination links.

The getPager() function returns an array of data and links. The first element of the array contains array of data and the second element contains pagination links.


foreach loop is used to display data. Before trying foreach loop, I had tried section loop but it didn’t work with pagination/pager. Smarty function ‘cycle’ is used to alternate row color of the table on which data is being displayed.


Download source code


Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed
  • Nice blog you have. You also most welcome to my world I mean to say my blog.

  • Hi Mukesh,

    Do you have a demo of this?


  • Sorry, I don’t have the demo. You can try it in your localhost.

  • Unknown

    i dont know why u provide only wrong code or incomplete code , it might be misguide everybody .i found your many code wrong or not complete if dont know your self dont misguide others.

  • All of my code had been tested before posting. I have written this article a long time back. Not tested in the latest version of PEAR / Smarty. There might be some upgrade issue.

    One more thing, in most of my articles, I have tried to be as descriptive as possible. Also, providing full source code. I have never tried to misguide others. I started this blog so that I could help others in programming and my intension will always be the same.