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: [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/

Re: [Jason] Pagination - the Awkward Way!

Hi, Jason -

No worries. I spent much of last night and almost all of today pulling the structure apart and rebuilding it again how I want it. The result works quite well and I've learned a lot along the way into the bargain.

Essentially, it's a pagination system for detail pages. It looks identical to the method raised by Damon, here...

page count at bottom with prev next links

...but uses different data to set-up the page numbers and generate the links.

Once I've tidied things up I'll give the code a proper run out in the forum...

:0)

Perch