How to display one image from a specific record?

7 posts by 2 authors in: Forums > CMS Builder
Last Post: August 12, 2009   (RSS)

By gkornbluth - August 10, 2009



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
The first CMS Builder reference book is now available on-line!







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

Hi gkornbluth,

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

Re: [chris] How to display one image from a specific record?

By gkornbluth - August 11, 2009

Thanks for looking at this. It all seems logical but I can't seem to get it to work. No matter what I do I either get undefined errors or a blank screen.

How would I modify the code I was using (above) to incorporate your code?

Thanks,

Jerry
The first CMS Builder reference book is now available on-line!







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

Hi gkornbluth,

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

Re: [chris] How to display one image from a specific record?

By gkornbluth - August 12, 2009

Chris,

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="" />
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [chris] How to display one image from a specific record?

By gkornbluth - August 12, 2009

Ah those $^@!)%)#* details again.

Can't thank you enough...

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php