Page 1 of 1

Need Help in Joomla! PHP code - News in more columns

Posted: Fri Oct 03, 2008 6:13 am
by finbiro
This is how it works now:
New row is created for every item, so the current code loks like this:

Code: Select all

 
 
<table>
    <?php foreach($list as $item) : ?>
        <tr><td>
            <div class="banneritem<?php echo $params->get( 'moduleclass_sfx' ) ?>"><?php
            echo modBannersHelper::renderBanner($params, $item);
            ?><div class="clr"></div>
            </div>
        </tr></td>
    <?php endforeach; ?>
</table>
 
 
I need to put items in 2 columns.

So:
now is ______ should be
1 __________ 1 2
2 __________3 4
3 __________ 5 6
4 __________ 7 8

Please help ASAP!

Re: Need Help! PHP code - News in more columns

Posted: Fri Oct 03, 2008 9:10 am
by Kadanis
How about using the index of the array rather than the foreach loop, and increment by 2 each time. Not sure what template engine you are using, but this should work as long as $item is equal to $list[$x]

Code: Select all

 
<table>
<?php
for ($x = 1; $x <= $list; $x +=2):
$item = $list[$x];
$item2 = $list[$x+1];
?>  
    <tr>
        <td>
            <div class="banneritem<?php echo $params->get( 'moduleclass_sfx' ) ?>">
                <?php echo modBannersHelper::renderBanner($params, $item);?>
                <div class="clr"></div>
            </div>
        </td>
        <td>
            <div class="banneritem<?php echo $params->get( 'moduleclass_sfx' ) ?>">
                <?php echo modBannersHelper::renderBanner($params, $item2);?>
                <div class="clr"></div>
            </div>
        </td>
    </tr>
<?php endfor;?>
</table>
 

Re: Need Help! PHP code - News in more columns

Posted: Fri Oct 03, 2008 11:10 am
by finbiro
Not working propperly. The page blocks.

php 5.2.5 / Joomla! 1.5

This is module called mod_banners.
The zipped file is in attachment if it helps.