Eternal_Student
asked on
Foreach loop question
Hi - I have a foreach loop where I want to split the output up so that I can display the content in 2 columns instead of 1.
At the minute I get the following HTML output:
<div id="itemExtraFields">
<div class="even typeTextarea group6"> <!-- ITEM 1 --></div>
<div class="odd typeTextarea group6"> <!-- ITEM 2 --></div>
<div class="odd typeTextarea group6"> <!-- ITEM 3 --></div>
<div class="even typeTextarea group6"> <!-- ITEM 4 --></div>
<div class="odd typeTextarea group6"> <!-- ITEM 5 --></div>
<div class="odd typeTextarea group6"> <!-- ITEM 6 --></div>
</div>
But What I really need to do is wrap a <div> around the 1st 4 items and then a <div> around the last 2. So I can style them as 2 columns.
Below is my php ... hopefully you can suggest the best solution for this.
Thanks
At the minute I get the following HTML output:
<div id="itemExtraFields">
<div class="even typeTextarea group6"> <!-- ITEM 1 --></div>
<div class="odd typeTextarea group6"> <!-- ITEM 2 --></div>
<div class="odd typeTextarea group6"> <!-- ITEM 3 --></div>
<div class="even typeTextarea group6"> <!-- ITEM 4 --></div>
<div class="odd typeTextarea group6"> <!-- ITEM 5 --></div>
<div class="odd typeTextarea group6"> <!-- ITEM 6 --></div>
</div>
But What I really need to do is wrap a <div> around the 1st 4 items and then a <div> around the last 2. So I can style them as 2 columns.
Below is my php ... hopefully you can suggest the best solution for this.
Thanks
<div class="itemExtraFields">
<?php foreach ($this->item->extra_fields as $key=>$extraField):?>
<div class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>">
<!--<span class="itemExtraFieldsLabel"><//?php echo $extraField->name; ?>:</span>-->
<span class="itemExtraFieldsValue"><?php echo $extraField->value; ?></span>
<div class="clear"></div>
</div>
<?php endforeach; ?>
</div>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.