display image from another table - showing only one
4 posts by 2 authors in: Forums > CMS Builder
Last Post: September 6, 2010 (RSS)
By Deborah - September 2, 2010
For each program, I want to select from a list of uploaded logos and have those display on the program detail page.
- display table name is "programs"
- "programs" contains a multi-value list field pull-down named "logo"
- the "logo" field gets options from the database table "logo_uploads"
Here's what I have in the viewer head element:
<?php
list($programsRecords, $programsMetaData) = getRecords(array(
'tableName' => 'programs',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$programsRecord = @$programsRecords[0]; // get first record
?>
<?php //display logos selected from list in other table, note both tables have same field name of 'logo'
$numsTabbedList = $programsRecord['logo'];
$numsTabbedList = trim($numsTabbedList);
$numsCommaList = str_replace("\t", ",", $numsTabbedList);
if ($numsCommaList) {
list($logo_uploadsRecords,) = getRecords(array(
'tableName' => 'logo_uploads',
'where' => "num IN ($numsCommaList)",
'allowSearch' => '0',
));
$logo_uploadsRecord = @$logo_uploadsRecords[0]; // get first record
}
else { $logo_uploadsRecords = array(); // empty array
}
?>
And in the body:
<?php
list($logo_uploadsRecords, $logo_uploadsMetaData) = getRecords(array(
'tableName' => 'logo_uploads',
'where' => "num ='{$programsRecord['logo']}'",
));
$logo_uploadsRecord = @$logo_uploadsRecords[0]; // get first record
?>
<?php if ($programsRecord['logo']): ?>
<?php foreach ($logo_uploadsRecord['logo'] as $upload): //display logos selected from list in logo_uploads table ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath2'] ?>" />
<?php endif ?>
<?php endforeach ?>
<?php endif ?>
Can anyone suggest where I may have gone wrong? Thanks for any help!
~ Deborah
Re: [Deborah] display image from another table - showing only one
By Chris - September 2, 2010 - edited: September 2, 2010
Your head code looks good, except that I don't think you'll need this line:
$logo_uploadsRecord = @$logo_uploadsRecords[0]; // get first record
I think you'll want to replace your body code (including the getRecords() call) with something like this:
<?php foreach($logo_uploadsRecords as $logo_uploadsRecord): ?>
<?php foreach ($logo_uploadsRecord['logo'] as $upload): //display logos selected from list in logo_uploads table ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath2'] ?>" />
<?php endif ?>
<?php endforeach ?>
<?php endforeach ?>
Does that help? Please let me know if you have any questions.
Chris
Re: [chris] display image from another table - showing only one
By Deborah - September 2, 2010
Thank you for your prompt assistance. I continued to be awed by the "power of CMS Builder" as well as the company's excellent support via this forum.
~ Deborah
Re: [Deborah] display image from another table - showing only one
By Chris - September 6, 2010
Glad I could help, and thanks for the kind words! :)
Chris