display image from another table - showing only one

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

Reviewing other posts to this forum, I managed to nearly accomplish my goal of displaying a list of images selected from another table. My problem is that instead of seeing the full list of selected images, only the most recently uploaded image is displaying.

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

Hi Deborah,

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.
All the best,
Chris

Re: [Deborah] display image from another table - showing only one

By Chris - September 6, 2010

Hi Deborah,

Glad I could help, and thanks for the kind words! :)
All the best,
Chris