using foreach loop to produce table

3 posts by 2 authors in: Forums > CMS Builder
Last Post: February 23, 2010   (RSS)

By jarvis - February 23, 2010 - edited: February 23, 2010

Hi All,

I hope someone can point me in the right direction. I've got the following code, which I'm trying to retrieve all the images from my clients list and produce a table with say 5 images per row, however, I've come unstuck. Here's my code:

<table width="600" border=1>
<tr>
<td>
<?php $i = 0; ?>
<?php foreach ($clientsRecords as $record):?>
<?php
foreach ($record['client_logo'] as $upload):
$float = (($i % 5) !== 0) ? '</td><td>' : '</td></tr><tr><td>';
?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="<?php echo $record['client_name'] ?>" />
<?php echo $float; ?>
<?php endforeach; ?>
<?php endforeach; ?>
</td>
</tr>
</table>


I hope someone can help! At the moment I simply get all the images listing down the page!

Many thanks

Re: [jarvis] using foreach loop to produce table

By jarvis - February 23, 2010

Sorted, was missing i++

<table class="client_category" width="600" align="center" border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="middle">
<?php $i = 0; ?>
<?php foreach ($clientsRecords as $record):?>
<?php foreach ($record['client_logo'] as $upload):?>
<?php $float = (($i % 5) !== 0) ? '</td><td>' : '</td></tr><tr><td valign="middle">'; ?>
<a href="<?php echo $record['_link'] ?>">
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="<?php echo $record['client_name'] ?>" />
</a>
<?php ++$i; ?>
<?php echo $float; ?>
<?php endforeach; ?>
<?php endforeach; ?>
</td>
</tr>
</table>


Hope that helps someone!

Thanks