Help sorting products into columns

5 posts by 2 authors in: Forums > CMS Builder
Last Post: September 30, 2008   (RSS)

By _kate_ - September 9, 2008

Hi,
I have used this code successfully on many pages after someone here gave it to me, however I have tried to add it to another page tonight and can't figure out what I have done wrong.

I need each new picture to display in a new column so the pictures would go horizontally across the page. The pop up image etc and everything is working fine, however the images are displaying one by one underneath each other in the same table cell instead of going into a new column.

Any help is appreciated!!!



<table border="0" cellpadding="0" cellspacing="0">
<tr>
<?php foreach ($projectsRecords as $record): ?>
<div class="project_name"><?php echo $record['title'] ?></div>
<td valign="top">

<?php foreach ($record['images'] as $upload): ?>
<a href="<?php echo $upload['urlPath'] ?>" class="productImages" rel="facebox"><img src="<?php echo $upload['urlPath'] ?>" height="100" /></a><br/>

</td>
<?php endforeach ?>

<?php $maxCols=5; if (@++$count % $maxCols == 0): ?></tr><tr><?php endif; ?>

<?php endforeach; ?>
</tr>
</table>

Re: [Dave] Help sorting products into columns

By _kate_ - September 29, 2008

Thanks! After fiddling and moving those as suggested I got it to work. It's funny how simply moving something below something else can make such a huge difference!

I have encountered a similar problem on another page of the same website that I can seem to solve.

I don't want the URL to be public so have sent that through to you in a PM so you can review it if needed. The code is below for anyone who can help.

I am trying to get the products to display in in groups of 5 columns under their sections. All the data is displaying fine, however I can't get them into columns properly. The first section works fine, however the ones after don't. They are displaying the first line of products with 2 columns, and then 5 for everything after, the next with 3 in the first line and so on. Can't figure out what I did wrong.


<?php
require_once "/urlremovedbyme/viewer_functions.php";

list($advanta_brochuresRecords, $advanta_brochuresMetaData) = getRecords(array(
'tableName' => 'advanta_brochures',
));

list($sturdyRecords, $sturdyMetaData) = getRecords(array(
'tableName' => 'sturdy',
));

list($freibergRecords, $freibergMetaData) = getRecords(array(
'tableName' => 'freiberg',
));

?>


<table border="0" cellpadding="0" cellspacing="0">
<tr>
<strong>Advanta</strong><br /><br />
<?php foreach ($advanta_brochuresRecords as $record): ?>
<?php if ($record['type'] != "Seating") ?>

<td width="200" align="center" valign="top" style="padding-bottom: 16px;">

<?php echo $record['product_title'] ?><br />

<?php foreach ($record['brochure'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" /><br/>
<?php elseif ($upload['isImage']): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" /><br/>
<?php else: ?>
<a href="<?php echo $upload['urlPath'] ?>" class="BrochureImg">
<?php foreach ($record['thumbnail'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" alt="" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" /><br/>
<?php elseif ($upload['isImage']): ?>
<img src="<?php echo $upload['urlPath'] ?>" alt="" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" vspace="6" /><br/>
<?php else: ?>
</a><br/>
<?php endif ?>
<?php endforeach ?>
<?php endif ?>
<?php endforeach ?>

<?php foreach ($record['brochure'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" /><br/>
<?php elseif ($upload['isImage']): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" /><br/>
<?php else: ?>
<a href="<?php echo $upload['urlPath'] ?>">View Brochure ></a><br/></td>

<?php endif ?>

<?php $maxCols=5; if (@++$count % $maxCols == 0): ?></tr><tr><?php endif; ?>
<?php endforeach ?>
<?php endforeach; ?>


</tr>
</table>
<br/>


<table border="0" cellpadding="0" cellspacing="0">
<tr>

<strong>Sturdy</strong><br /><br />
<?php foreach ($sturdyRecords as $record): ?>
<?php if ($record['type'] != "Seating") ?>

<td width="200" align="center" valign="top" style="padding-bottom: 16px;">

<?php echo $record['title'] ?><br />

<?php foreach ($record['brochure'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" /><br/>
<?php elseif ($upload['isImage']): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" /><br/>
<?php else: ?>
<a href="<?php echo $upload['urlPath'] ?>" class="BrochureImg">
<?php foreach ($record['thumbnail'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" alt="" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" /><br/>
<?php elseif ($upload['isImage']): ?>
<img src="<?php echo $upload['urlPath'] ?>" alt="" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" vspace="6" /><br/>
<?php else: ?>
</a><br/>
<?php endif ?>
<?php endforeach ?>
<?php endif ?>
<?php endforeach ?>


<?php foreach ($record['brochure'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" /><br/>
<?php elseif ($upload['isImage']): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" /><br/>
<?php else: ?>
<a href="<?php echo $upload['urlPath'] ?>">View Brochure ></a><br/></td>

<?php endif ?>

<?php $maxCols=5; if (@++$count % $maxCols == 0): ?></tr><tr><?php endif; ?>
<?php endforeach ?>
<?php endforeach; ?>

</tr>
</table>


....ETC ETC ETC

Re: [AgentBristow] Help sorting products into columns

By Dave - September 29, 2008

Hi AgentBristow,

When using that little code snippet multiple times on the same page just use a different variable instead of $count or it will remember the count from the last section and be continuing with that.

Instead of this:

<?php $maxCols=5; if (@++$count % $maxCols == 0): ?></tr><tr><?php endif; ?>

Use this:

<?php $maxCols=5; if (@++$count1 % $maxCols == 0): ?></tr><tr><?php endif; ?>

<?php $maxCols=5; if (@++$count2 % $maxCols == 0): ?></tr><tr><?php endif; ?>

<?php $maxCols=5; if (@++$count3 % $maxCols == 0): ?></tr><tr><?php endif; ?>

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Help sorting products into columns

By _kate_ - September 30, 2008

Worked perfectly! Thanks for your help :)