Main
Index
Search
Posts
Who's
Online
Log
In

Home: Products: CMS Builder:
Previous / Next Problem

 

 


pothompson
User

Sep 1, 2010, 10:57 PM

Post #1 of 2 (602 views)
Shortcut
Previous / Next Problem Can't Post

I'm not sure if I'm doing this the right way, but I have two sections, categories and products and am trying to use previous and next buttons depending on the number of products in the selected category.

So far, I have a call to getRecords for the categories as follows:

list($categoriesRecords, $categoriesMetaData) = getRecords(array(
'tableName' => 'categories',
'where' => whereRecordNumberInUrl(1),
));
$categoriesRecord = @$categoriesRecords[0]; // get first record
The URL on the initial category page looks like this: /collection.php/sanctuary-3/

Then, I have a call to getRecords for the products like this

list($productsRecords, $productsMetaData) = getRecords(array(
'tableName' => 'products',
'where' => 'category like "%\t'.$categoriesRecord['num'].'\t%"',
'perPage' => 20,
'useSeoUrls' => true,
));

When I go to page 2, using the generated next button, the following URL is called
/collection.php/sanctuary-3/page-2/

The problem with this is that the call to whereRecordNumberInUrl() from step 1, finds the '2' from the page part of the URL and displays page 2 of category 2, not of category 3.

I hope this makes sense and am sure I'm probably not handling this in the best way so any help would be appreciated.

Thanks.


Jason
Staff / Moderator


Sep 2, 2010, 9:19 AM

Post #2 of 2 (573 views)
Shortcut
Re: [pothompson] Previous / Next Problem [In reply to] Can't Post

Hi,

What we need to do is not use whereRecordNumberInUrl(1) when there is not page information in the url. What we need to do is to get the category number from the URL, this should be the first variable.

Try using this code to select your category records:


Code
 
if($_REQUEST){
$catKey = array_keys($_REQUEST);
$catKey = $catKey[0];
$catNum = "num=".intval($_REQUEST[$catKey]);
}
else{
$catNum = whereRecordNumberInUrl(1);
}


list($categoriesRecords, $categoriesMetaData) = getRecords(array(
'tableName' => 'categories',
'where' => $catNum,
));


Give that a try and let me know if that works for you.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Programmer 
interactivetools.com

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