I'm trying to wrap two columns inside of a row div from inside a php loop.
I came up with this test but it fails no matter what I do.. This is the closest I can come, I can't see where this logic fails.
Take a look:
<?php $i = 0; ?>
<?php while($i < 11) : ?>
<?php if ($i % 2 === 0) : ?>
<div class="row">row
<?php endif; ?>
<span><?php echo "[" . $i . "]"; ?></span>
<?php if (!$i % 2 === 0) : ?>
/row
</div>
<?php endif; ?>
<?php $i++; ?>
<?php endwhile; ?>
The produced result:
row [0] [1] /row
row [2] /row
[3] /row
row [4] /row
[5] /row
row [6] /row
[7] /row
row [8] /row
[9] /row
row [10] /row
Here we can see that the first row is working great but then it becomes flawed somewhere in the logic, question is where?
Made a little changes to your code.
<?php $i = 0;
while($i <= 11) :
if($i%2==0){
echo '<div class="row"> Row';
}
echo "[" . $i . "]";
if($i%2!=0){
echo " row </div>";
}
$i++;
endwhile; ?>
It will output
Row[0][1] row
Row[2][3] row
Row[4][5] row
Row[6][7] row
Row[8][9] row
Row[10][11] row
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With