list items per page and pagination

4 posts by 2 authors in: Forums > CMS Builder
Last Post: June 15, 2011   (RSS)

By ikanizaj - June 14, 2011

Is it possible to create 20 items per page, but that pagination goes ten records at the time.

What I would like is to create first ten items displaying title, images, summary, etc. and next ten items only title.

Then I would like, when I click on next page, to display ten items (from the first page that had only titles) with title, images, summary, and next ten items with only titles? Is that possible?
--
Igor Kani¾aj

Re: [ikanizaj] list items per page and pagination

By Jason - June 14, 2011

Hi Igor,

So to clarify, one your first page, you want to display 20 items, and then you want to display 10 items on each page after. Is that right?

One options would be, instead of using perPage, use the limit and offset options.

For example, if $_REQUEST['page'] = 1 or has no value, you would use:
offset => 0,
limit => 20

If the page is greater than 1, you would use
offset => $page * 10,
limit => 10,

Hope this helps get you started.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [ikanizaj] list items per page and pagination

By Jason - June 15, 2011

Hi Igor,

Sure, you will have to use the offset & limit method. You can set your offset variable like this:

$page = intval(@$_REQUEST['page']);
$offset = (($page - 1) * 10) - 1;
if ($offset < 0) { $offset = 0;}

list ($articleRecords, $articleMetaData) = getRecords(array(
'tableName' => 'articles',
'allowSearch' => false,
'offset' => $offset,
'limit' => 20,
));


The one issue here is that if you look at the metaData variable, you won't have the page numbers and prevPageLink/nextPageLink automatically generated for you. You will have access to totalRecords, pageResultsStart, and pageResultsEnd. You'll have to manually create your links that include the page numbers.

Hope this helps get you started.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/