list items per page and pagination

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

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: [Jason] list items per page and pagination

By ikanizaj - June 14, 2011

no no, 20 items on every page. First ten with more detail, and other ten with just title. But on second page, first ten with more detail should be the one that were just title on previous page.
--
Igor Kani¾aj

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/