2 posts by 2 authors in: Forums > CMS Builder
Last Post: September 4, 2009   (RSS)

Re: [InHouse] I think I need a join but I'm not sure.

By Chris - September 4, 2009

Hi InHouse,

Here's how I did it. First, my STEP 1 code. You may need to change section and field names if ours aren't the same as mine:

list($eventRecords, $eventMetaData) = getRecords(array(
'tableName' => 'event',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$eventRecord = @$eventRecords[0]; // get first record

// show error message if no matching record is found
if (!$eventRecord) {
print "Record not found!";
exit;
}

// fetch sponsors
$sponsorNums = join(", ", split("\t", trim($eventRecord['sponsors'])));
if ( $sponsorNums ) {
list($sponsorRecords, $sponsorMetaData) = getRecords(array(
'tableName' => 'sponsor',
'where' => "num IN ($sponsorNums)",
));
}
else {
$sponsorRecords = array();
}


And then, later in the page, when you want to display your sponsor images:

<?php foreach ($sponsorRecords as $sponsorRecord): ?>
<?php foreach ($sponsorRecord['graphic'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt='' /><br/>

<?php elseif ($upload['isImage']): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt='' /><br/>

<?php else: ?>
<a href="<?php echo $upload['urlPath'] ?>">Download <?php echo $upload['filename'] ?></a><br/>

<?php endif ?>
<?php endforeach ?>
<?php endforeach; ?>


I hope this helps! Please let me know if you have any trouble getting your page working, or if you have any questions.
All the best,
Chris