3 column display

7 posts by 2 authors in: Forums > CMS Builder
Last Post: June 23, 2014   (RSS)

Hi

I am using the three column list display

<table width="618" border="0"> <tr>
             
             

             
<h1><?php echo $gold_sponsors_titleRecord['title']; ?></h1>
             
<?php if ($gold_sponsors_titleRecord['intro']): ?><p style="line-height: 120%"><font face="Arial" style="font-size: 12px"><?php echo htmlencode($gold_sponsors_titleRecord['intro']) ?></font></p><?php endif; ?>

<?php foreach ($gold_sponsorsRecords as $record): ?><td>  <a target="_blank" href="<?php echo $record['_link'] ?>">

<img border="0" src="http://www.meetingonthegreen.com.au/cmsAdmin/uploads/<?php echo htmlencode($record['logo_name']) ?>" width="170"></a></td>            

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

however, one image is appearing on it's own above the other (see http://www.meetingonthegreen.com.au/sponsorship_opportunities2.php (gold sponsors and partners).  Can someone please advise how to fix this.

Thanks in advance.

By claire - June 19, 2014

Hi there

I don't think there's an issue with your code. Are you resetting the $count variable after every header?

--------------------

Claire Ryan
interactivetools.com

Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Hi Claire

What does that mean - resetting the $count variable?  Where/what should that look like?

Thanks

By claire - June 20, 2014

The $count variable is a counter that basically ticks up every time a column is added. It's used to determine how many columns there should be in each row. Here's how the code works:

<table width="618" border="0">
  <tr>
    <h1><?php echo $gold_sponsors_titleRecord['title']; ?></h1>      
    <?php if ($gold_sponsors_titleRecord['intro']): ?><p style="line-height: 120%"><font face="Arial" style="font-size: 12px"><?php echo htmlencode($gold_sponsors_titleRecord['intro']) ?></font></p><?php endif; ?>

This starts a new set of columns and adds the title (Gold Sponsors, Partners, etc).

<?php foreach ($gold_sponsorsRecords as $record): ?>

This starts the loop that adds all the columns with the logos in them.

<td><a target="_blank" href="<?php echo $record['_link'] ?>"><img border="0" src="http://www.meetingonthegreen.com.au/cmsAdmin/uploads/<?php echo htmlencode($record['logo_name']) ?>" width="170"></a></td>            

This adds the columns themselves.

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

This bit is the important part. Basically what it does is make the counter tick up by one, and then it checks to see if the counter number is exactly divisible by 3. If so, it starts a new row of columns.

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

This ends the loop and closes the set.

So what should happen is that the counter should be set back to zero every time it starts a new section. If it's not being reset properly, then you get odd behaviour like you're seeing right now.

Best thing to do is show me the entire code for that page. If you're looking for it, it should be something like

$count = 0;

--------------------

Claire Ryan
interactivetools.com

Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Hi Claire

Thanks for this, but that's what I have (or not sure if your last line of code was meant to contain something other than $count = 0;  ?  I have attached the file to see whether you can shed any more info on this. 

Thanks, that fixed it.