use COUNT and insert DIV of X in X quantity

1

Assuming I have a database with X elements! At the time of the query I'm going to use count to see how many rows I have! I would like to divide this result and divide by any number, in this case I will use the value of 3, taking into consideration that I had a return of 9 lines, the result will be 3!

So at the time of echo , I would like to insert one for div in "back" of every 3 results. I would like the result to look like this!

<div class="inserida_pela_php">
    <div class="div_qualquer"> 1 </div>
    <div class="div_qualquer"> 2 </div>
    <div class="div_qualquer"> 3 </div>
</div>

<div class="inserida_pela_php">
    <div class="div_qualquer"> 4 </div>
    <div class="div_qualquer"> 5 </div>
    <div class="div_qualquer"> 6 </div>
</div>

<div class="inserida_pela_php">
    <div class="div_qualquer"> 7 </div>
    <div class="div_qualquer"> 8 </div>
    <div class="div_qualquer"> 9 </div>
</div>
    
asked by anonymous 22.05.2015 / 04:14

1 answer

2
<div class="inserida_pela_php">
<?php
$count = 9;
for ($i = 1; $i <= $count; $i++) {
    echo '<div class="div_qualquer">' . $i . '</div>' . "\n";
    if ($i % 3 == 0 && $i != $count) {
        echo '</div><div class="inserida_pela_php">' . "\n";
    }
}
?>
</div>

Tuning for your needs

    
22.05.2015 / 04:47