Pagination - the Awkward Way!

5 posts by 2 authors in: Forums > CMS Builder
Last Post: August 19, 2010   (RSS)

I want to set-up a form of pagination between (detail) pages assigned to the current $selectedCategory. I appreciate there is already a method of doing this, along the lines of...

.....

<a href="<?php echo $itemRecordMetaData['prevPageLink'] ?>">&lt;&lt; prev</a>

.....

<?php foreach (range(1,$RecordMetaData['totalPages']) as $page): ?>

.....

<a href="<?php echo $RecordMetaData['nextPageLink'] ?>">next &gt;&gt;</a>

.....


Although this structure is fine, it's intended for use on list pages so requires certain modifications to the list() code to make it work.

Also, the way in which the next/prev links function is different to the normal approach and can cause problems. (i.e. such pages do not use/require 'where' => whereRecordNumberInUrl(1) ).

My question is; can the pagination structure outlined above be configured in such a way as to generate normal links which do use whereRecordNumberInUrl(1)?

:oS

Perchpole

Re: [Perchpole] Pagination - the Awkward Way!

By Jason - August 18, 2010

Hi Perchpole,

Yes, you can create custom links for use in the pagination for pages that do use whereRecordNumberInUrl().

The best way to format your link would be like this:
myPage.php?num=RECORDNUMBER&page=PAGENUMBER

If you're using a format that doesn't use the num variable in the URL string (such as myPage.php?my-title-NUMBER), you can still do this by making sure the record number is the last number in the string (ie. myPage.php?page=PAGENUMBER&my-title-NUMBER)

Hope this helps.
---------------------------------------------------
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] Pagination - the Awkward Way!

Hi, Jason -

Thanks for your tips but I think there's a bit more to it than that...

The problem is how to generate/assign the correct page number to the link.

Part of the pagination code block looks like this...
<?php foreach (range(1,$itemRecordMetaData['totalRecords']) as $page): ?>
<?php if ($page == $current_page): ?>
<strong><?php echo $page; ?></strong>
<?php else: ?>
<a href="./index.php?category=<?php echo $selectedCategory['num'] ?>&page=<?php echo $WHAT['num'] ?>">Link</a>
<?php endif ?>
<?php endforeach; ?>

The foreach loop does not pass down any record information - so there is no way to pull the record 'num' into the link.

If I were to use $page it would just be an arbitrary number which wouldn't match the actual record number as required by whereRecordNumberInUrl(1).

:0S

Perch

Re: [Perchpole] Pagination - the Awkward Way!

By Jason - August 19, 2010

Hi,

I'm not sure if I completely understand what you're trying to do. The pagination is used when you are returning multiple records from the database but only want to display a certain number of them at a time. When you're using "whereRecordNumberInUrl()", you're trying to retrieve only 1 specific record. There would be no other pages.

Is the problem you're encountering that you're retrieve information from multiple tables at the page number in the url is interfering with other getRecords functions?

Let me know and I'll take a closer look into this.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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