Combining array_merge with perPage

5 posts by 2 authors in: Forums > CMS Builder
Last Post: May 17, 2016   (RSS)

By JeffC - May 12, 2016 - edited: May 12, 2016

Hi 

I am outputting entries from 3 tables into 1 list page using array_merge. Currently the code below shows everything.

// load list records from 'review'
list($reviewRecords, $listMetaData) = getRecords(array(
'tableName'   => 'review',
'loadUploads' => true,
'allowSearch' => true,
));
  
  
// load list records from 'interview'
list($interviewRecords, $listMetaData) = getRecords(array(
'tableName'   => 'interview',
'loadUploads' => true,
'allowSearch' => true,
));
  
  
// load list records from 'profile'
list($friendsRecords, $listMetaData) = getRecords(array(
'tableName'   => 'profile',
'loadUploads' => true,
'allowSearch' => true,
));

 
$listRecords = array_merge($reviewRecords, $interviewRecords, $profileRecords);

I would like to show 12 items per page, but importantly it must be the 12 most recent entries from ALL the tables that have been merged.

As noted by Jason in the forum back in 2011 the perPage option will only limit the number of record at the time the query takes place and can't be applied afterwards. Jason also linked to this post but the link is broken now: http://www.interactivetools.com/forum/gforum.cgi?post=88664#88664.

Any help gratefully received

Thanks

Jeff

By JeffC - May 13, 2016

Hi Ross

Thanks for your help.

A great solution, that's got me on the right track, but it isn't quite what I was after.

Your solution works perfectly to show the most recent 12 entries from all lists - but it only displays the first 12. I would like to show all of the entries, but 12 per page. i.e.

Page 1 = 1-12

Page 2 = 13-24

Page 3 = 25-36 etc

Jeff

By ross - May 17, 2016

Hi Jeff

I see what you mean and there isn't really a simple solution and I'd need to build something custom for you through consulting.  

You can send me an email to consulting@interactivetools.com if you'd like to have that conversation.

Let me know what you think.

Thanks!

-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

By JeffC - May 17, 2016

Thanks Ross, I'll send you an email now

Jeff