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: [Jason] Records from multiple sections into one viewer

By Mikey - July 12, 2011

Jason, I tried to disable the //'perPage' in the load records for each record, but all the records load on one page. Is it possible to remove the 'perPage' from the load records for each record and apply the 'perPage' to the $mediaMergeRecords so there's only one 'perPage' that controls all the merged records?

// 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);
// after all records are merged, limit to 13 perPage
$mediaMergeRecords = array_slice($mediaMerge, 0, 13);



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.