Previous / Next Problem
2 posts by 2 authors in: Forums > CMS Builder
Last Post: September 2, 2010 (RSS)
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.
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.
Re: [pothompson] Previous / Next Problem
By Jason - September 2, 2010
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:
Give that a try and let me know if that works for you.
Hope this helps.
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:
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 - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/