getPrevAndNextRecords() - Hidden Records?
10 posts by 4 authors in: Forums > CMS Builder
Last Post: February 2, 2015 (RSS)
Just a quickie...
Does getPrevAndNextRecords() observe the hidden record status? If so, is there any way to turn it off?
Thanks,
Perch
By claire - February 2, 2015
Just checked the codebase for CMSB to be sure, but as far as I can see it ignores the hidden record flag.
Claire Ryan
interactivetools.com
Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Hi, Claire -
That's interesting. I've done a couple of tests and my prev/next pagination gets flaky when a page is "hidden". Perhaps it's the data I'm feeding into getPrevAndNextRecords()? My code looks like this:
$optionsArray = array(
'tableName' => 'pages',
'where' => " parentNum = '".intval($selectedPage['parentNum'])."' ",
//'where' => " parentNum = '".intval($selectedPage['parentNum'])."' && hidden != 1 ", /*Alternative*/
'recordNum' => $selectedPageNum
);
list($prevRecord, $nextRecord, $firstRecord, $lastRecord) = getPrevAndNextRecords($optionsArray);
What does getPrevAndNextRecords() need from the array in order to work properly?
:0/
Perch
By claire - February 2, 2015
That '&&' should be 'AND'. The double ampersand logical operator isn't supported in MySQL, as far as I know.
Claire Ryan
interactivetools.com
Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Hi, Claire -
Thanks for the tip - but it still doesn't work.
Here's the thing, if I filter out hidden records - using this where statement...
'where' => " parentNum = '".intval($selectedPage['parentNum'])."' AND hidden != 1",
...it works fine.
However, if I don't filter out the hidden records...
'where' => " parentNum = '".intval($selectedPage['parentNum'])."' ",
...the prev/next sequence breaks.
Something somewhere is tripping over hidden records.
Perch
By Damon - February 2, 2015
Hi Perch,
How about just using this code to override and show hidden records:
'ignoreHidden' => true, // don't hide records with hidden flag set
Let me know if this does what you need.
Damon Edis - interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Hi, Damon -
I didn't know I could add that to the $optionsArray. I assumed it was for getRecords() calls only?
Perch
By Damon - February 2, 2015
I didn't know I could add that to the $optionsArray. I assumed it was for getRecords() calls only?
Sorry, I use this for getRecords, missed the $optionsArray part. Don't think this will work in this case.
Still looking into this.
Damon Edis - interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
By Dave - February 2, 2015
Hi Perch,
The getPrevAndNextRecords() function is a stand-alone function. It doesn't give any specific meaning to 'hidden' or any of the other CMSB special fields. And neither would/should MySQL. It's just another field as far as MySQL is concerned.
So it "should' just work...
>...the prev/next sequence breaks.
What do you mean by "breaks"? That no record number is returned? Or that the order of records is different than what was expected?
Here's some things to check:
- What is the "Order By" set to in the section editor for that section?
- You could try manually setting an 'orderBy' option so you're explicitly stating the order you want
- Does this work: AND COALESCE(`hidden`,0) != 1
- Write another viewer that prints a list of records with the matching parentNum and orderBy and compare the ordering
Also, what version of CMSB and MySQL are you using? We've seen issues with that function in older versions of MySQL or CMSB. It's because we use some advanced MySQL features to keep track of the record numbers and they didn't always work correctly on some servers.
Let me know what you find. Thanks!
interactivetools.com
By claire - February 2, 2015
I think I might know what's going on here.
getPrevAndNextRecords() depends on a call to getRecords() after it determines which records it needs. That call uses some default settings, meaning it DOES actually drop all hidden records. There's no way to turn it off that I can see. The getPrevAndNextRecords code fails after that point because it expects a particular record that isn't returned by the getRecords call.
Maybe Dave or Damon can confirm if I have this right?
Claire Ryan
interactivetools.com
Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/