Records from multiple sections into one viewer

16 posts by 6 authors in: Forums > CMS Builder
Last Post: July 13, 2011   (RSS)

By InHouse - August 14, 2009

Thank you! This is just what I needed for the current project I'm working on!

You guys are the best!

J.

Re: [chris] Records from multiple sections into one viewer

By Ryan - December 14, 2010

Brilliant just what i needed, thanks Chris!

Re: [Chris] Records from multiple sections into one viewer

By Mikey - July 11, 2011

Chris is it possible to create a function to sort by date and limit the records perPage after all records have been merged using some code like that seen in red and if it is possible, can you show me how?

// sort them by date
function createdDateCompareFunction($a, $b) { return -strcmp($a['createdDate'], $b['createdDate']); }
usort($mediaMerge, 'createdDateCompareFunction');

// after all records are merged, limit to 13 perPage
$mediaMergeRecords = array_slice($mediaMerge, 0, 9);


Here's the code I'm working with:
// load records
list($galleryRecords, $galleryMetaData) = getRecords(array(
'tableName' => 'gallery',
'perPage' => '7',
'orderBy' => 'createdDate DESC',
));

// load records
list($newsRecords, $newsMetaData) = getRecords(array(
'tableName' => 'news',
'perPage' => '2',
'orderBy' => 'createdDate DESC',
));

// load records
list($_incoming_mailRecords, $_incoming_mailMetaData) = getRecords(array(
'tableName' => '_incoming_mail',
'perPage' => '4',
'orderBy' => 'createdDate DESC',
));

foreach($_incoming_mailRecords as &$record) {
$record['title'] = $record['subject'];
$record['media_description'] = $record['text'];
//$record['media_description'] = $record['html'];
$record['media'] = $record['attachments'];
}
unset($record);

//////////////////////////// Load Multiple Records Array ///////////////////////
$mediaMerge = array();
$mediaMerge = array_merge($galleryRecords, $newsRecords, $_incoming_mailRecords);

// sort them by date

// after all records are merged, limit to 13 perPage

Re: [zick] Records from multiple sections into one viewer

By Jason - July 12, 2011

Hi Zick,

In your code, you are only getting the first 9, elements of the array, for 13, try this:

// after all records are merged, limit to 13 perPage
$mediaMergeRecords = array_slice($mediaMerge, 0, 13);


You can then loop through $mediaMergeRecords normally.

Hope this helps, please let us know if you run into any issues.
---------------------------------------------------
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: [zick] Records from multiple sections into one viewer

By Jason - July 13, 2011

Hi Zick,

I think you're on the right track. If you return all record for each section, then merge them into one array, you can implement a type of "perPage" by using a for loop to loop through a certain number of elements in the array.

Take a look at this post:
http://www.interactivetools.com/forum/gforum.cgi?post=88633#88633

This shows an example of creating pagination for a category list. You can use the same basic idea to control the number of records you output from your merged array.

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/