Pull in 1 item from two sections on same page

5 posts by 2 authors in: Forums > CMS Builder
Last Post: September 23, 2013   (RSS)

By TheSeen - September 20, 2013

Hi all ...

I have two sections in CMS builder both containing uploaded image files (home images & ipad home images).

I am trying to load a random one from each section into the same page ... is this possible?

Here's the step 1 load records code I've been trying to get working:

<?php header('Content-type: text/html; charset=utf-8'); ?>
/* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */

// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/home/sites/XXXXXXXXXXXX/public_html/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

// load records from 'home_images'
list($home_imagesRecords, $home_imagesMetaData) = getRecords(array(
'tableName' => 'home_images',
'limit' => '1',
'orderBy' => 'RAND()',
'loadUploads' => true,
'allowSearch' => false,

// load records from 'ipad_home_images'
list($ipad_home_imagesRecords, $ipad_home_imagesMetaData) = getRecords(array(
'tableName' => 'ipad_home_images',
'limit' => '1',
'orderBy' => 'RAND()',
'loadUploads' => true,
'allowSearch' => false,


By TheSeen - September 20, 2013

Hi Jason ... thanks for the feedback.

Both sections are multi-record sections with a number of single uploads.

I think the code you suggested was based on a single record sections with numbers uploads within the upload field?

By Jason - September 20, 2013


Okay, so each record has a single upload in it?  In that case, the code you had originally should be fine, as it would load a random record from each section.  When you use your original code, do you run into any issues?

Jason Sauchuk - Project Manager

Hire me! Save time by getting our experts to help with your project.

By TheSeen - September 23, 2013

Hi Jason ...

Yep sorted.

Original code was fine ... I'd just placed the placeholder tags slightly out of the right place. I have the ipad specific images loading into a media query specifically for portrait tablet users.