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: [AgentBristow] Help sorting products into columns

By Dave - September 9, 2008

Hi AgentBristow,

Is a public url available that shows the page in progress? And do you have a mockup or example page that shows what you want it to look like?

The standard process I follow is to get my mockup looking the way I want (often that's the hardest part) and then view source on that and the CMS generated version and see what the difference is (and try and fix that).

Based on the posted code it looks like the first div needs to come after the td. Then the same div and td need to go after the second foreach. I'm not sure what the format is suppose to be though.

Are there multiple records on the page? Do you want one row of images for each record or just one long row of images wrapping at the 5th column?

Let me know and I'll try and help! :)
Dave Edis - Senior Developer
interactivetools.com

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 :)