How to display one image from a specific record?
7 posts by 2 authors in: Forums > CMS Builder
Last Post: August 12, 2009 (RSS)
I’ve got a multi record section editor with one image upload field which allows only one image to be uploaded.
I know that I can display the image from the first record using <?PHP break ?>
As in:
list($affiliationsRecords, $affiliationsMetaData) = getRecords(array(
'tableName' => 'affiliations',
));
and
<?php foreach ($affiliationsRecords as $record): ?>
<?php foreach ($record['logo'] as $upload): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" />
<?php endforeach ?>
<?PHP break ?>
<?php endforeach ?>
How would I display an image from a specific record, say record 4?
Also, if I had multiple uploads in each upload field, how would I specify record 4 image 3?
I’ve done this with a single record editor but I’m stuck with the multi record implementation.
I looked through all of the posts that I thought would be relevant and know that I must be missing something.
Thanks,
Jerry Kornbluth
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Re: [gkornbluth] How to display one image from a specific record?
By Chris - August 11, 2009
If $affiliationsRecords is a list of all your records, then $affiliationsRecords[0] will give you the first record, $affiliationsRecords[1] will give you the second, etc. It's a little confusing that the counting starts at 0 instead of 1.
$affiliationsRecords[3]['logo'][2] will grab the fourth record ([3]), its list of images (['logo']), and select its third image ([2]).
e.g.
<?php $myImage = $affiliationsRecords[3]['logo'][2]; ?>
<img src="<?php echo $myImage['thumbUrlPath'] ?>" width="<?php echo $myImage['thumbWidth'] ?>" height="<?php echo $myImage['thumbHeight'] ?>" alt="" />
Hope this helps!
Chris
Re: [chris] How to display one image from a specific record?
How would I modify the code I was using (above) to incorporate your code?
Thanks,
Jerry
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Re: [gkornbluth] How to display one image from a specific record?
By Chris - August 12, 2009
I'm afraid there's not really a middle ground between the two approaches.
Can you post your PHP page and the exact error you get?
Chris
Re: [chris] How to display one image from a specific record?
I just know that I'm going to feel stupid when this is solved, but here goes:
Here's the code at the head of my page
<?php
require_once "/hsphere/local/home/c268311/durgagarcia.com/cmsAdmin/lib/viewer_functions.php";
list($affiliationsRecords, $affiliationsMetaData) = getRecords(array(
'tableName' => 'affiliations',
));
?>
And in the body:
<?php $myImage = $affiliationsRecords[1]['logo']; ?>
<img src="<?php echo $myImage['thumbUrlPath'] ?>" width="<?php echo $myImage['thumbWidth'] ?>" height="<?php echo $myImage['thumbHeight'] ?>" alt="" />
Here are the error messages
<img src="
Notice: Undefined index: thumbUrlPath in /hsphere/local/home/c268311/durgagarcia.com/imagetest1.php on line 44
" width="
Notice: Undefined index: thumbWidth in /hsphere/local/home/c268311/durgagarcia.com/imagetest1.php on line 44
" height="
Notice: Undefined index: thumbHeight in /hsphere/local/home/c268311/durgagarcia.com/imagetest1.php on line 44
" alt="" />
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Re: [gkornbluth] How to display one image from a specific record?
By Chris - August 12, 2009 - edited: August 12, 2009
$affiliationsRecords[1]['logo'] refers to the list of images. You need to use $affiliationsRecords[1]['logo'][0] if you want to refer to a specific image ([0] gives you the first one.)
Best of luck!
Chris
Re: [chris] How to display one image from a specific record?
Can't thank you enough...
Jerry
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php