Building table for uploads (photos)....
3 posts by 2 authors in: Forums > CMS Builder
Last Post: January 31, 2012 (RSS)
By HDLLC - January 31, 2012
I've been able to build a table (ie: four across images, then start new row, repeat) using upload fields for images - but trying a different way where the field allows multiple images, and I want them to show in a nice table 4 across per row.
Here's what I did have -
Doesn't work with an upload field where I have 20 images per record. That code above works for multiple records.
How can I do this type of table building when I have an upload field, in one record, that has multiple images per upload ?
Hope I'm explaining this right... Thanks much in advance!
---Jeff
Here's what I did have -
<table width="133" border="0" align="center" cellpadding="3" cellspacing="3">
<tr>
<?php foreach ($live_buckeye_deer_camsRecords as $record): ?>
<td align="center" valign="top"><?php foreach ($record['photos'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<a href="<?php echo $record['_link'] ?>"> <img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" border="0" /></a><br/>
<?php elseif ($upload['isImage']): ?>
<a href="<?php echo $record['_link'] ?>"><img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" border="0" /></a><br/>
<?php else: ?>
<a href="<?php echo $upload['urlPath'] ?>">No Thumbnail Available</a><br/>
<?php endif ?>
<?php endforeach ?>
</td>
<?php $maxCols=4; if (@++$count % $maxCols == 0): ?>
</tr>
<tr>
<?php endif; ?>
<?php endforeach; ?>
</tr>
</table>
<div align="center"><br />
<br />
<?php if ($live_buckeye_deer_camsMetaData['invalidPageNum']): ?>
Results page '<?php echo $live_buckeye_deer_camsMetaData['page']?>' not found, <a href="<?php echo $live_buckeye_deer_camsMetaData['firstPageLink'] ?>">start over >></a>.<br/>
<br/>
<?php elseif (!$live_buckeye_deer_camsRecords): ?>
No records were found!<br/>
Doesn't work with an upload field where I have 20 images per record. That code above works for multiple records.
How can I do this type of table building when I have an upload field, in one record, that has multiple images per upload ?
Hope I'm explaining this right... Thanks much in advance!
---Jeff
Re: [HDLLC] Building table for uploads (photos)....
By Jason - January 31, 2012
Hi Jeff,
You're actually very close.
What you have here is an outer loop (looping through your records) and an inner loop (looping through the images for a single record). The problem here is that your <td> tags and your column counting code is in your outer loop. This means that each record will have a single cell with all of their images in it, with a maximum of 4 records (cells) per row.
To have it so you get 4 images per row, regardless of the record they are coming from, you need to move your <td> and column counting code into the inner loop like this:
Hope this helps get you started
You're actually very close.
What you have here is an outer loop (looping through your records) and an inner loop (looping through the images for a single record). The problem here is that your <td> tags and your column counting code is in your outer loop. This means that each record will have a single cell with all of their images in it, with a maximum of 4 records (cells) per row.
To have it so you get 4 images per row, regardless of the record they are coming from, you need to move your <td> and column counting code into the inner loop like this:
<table width="133" border="0" align="center" cellpadding="3" cellspacing="3">
<tr>
<?php foreach ($live_buckeye_deer_camsRecords as $record): ?>
<?php foreach ($record['photos'] as $upload): ?>
<td align="center" valign="top">
<?php if ($upload['hasThumbnail']): ?>
<a href="<?php echo $record['_link'] ?>"> <img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" border="0" /></a><br/>
<?php elseif ($upload['isImage']): ?>
<a href="<?php echo $record['_link'] ?>"><img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" border="0" /></a><br/>
<?php else: ?>
<a href="<?php echo $upload['urlPath'] ?>">No Thumbnail Available</a><br/>
<?php endif ?>
</td>
<?php $maxCols=4; if (@++$count % $maxCols == 0): ?>
</tr>
<tr>
<?php endif; ?>
<?php endforeach ?>
<?php endforeach; ?>
</tr>
</table>
Hope this helps get you started
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Re: [Jason] Building table for uploads (photos)....
By HDLLC - January 31, 2012
Thanks, Jason! Works like a champ!