PHP: Group data without using 'group_by'

0

Does anyone know how to group data without using group_by in the query?

I need every 10

results
to create a div , that is, 10 records within each div I do not care about values.

<?php foreach($resultados->result() as $resultado){ ?>
    <?php for($i = 0; $i <= 10; ++$i){ ?>
        <div>
    <?php } ?>
        <?=$resultado->id?>
    <?php for($i = 0; $i <= 10; ++$i){ ?>
        </div>
    <?php } ?>
<?php }// foreach ?>
    
asked by anonymous 22.07.2018 / 03:50

1 answer

0

One way to do this would be to use an auxiliary counter ( $c ) and module ( %) .

Example:

$c = 0;
foreach($resultados->result() as $resultado){

    if ($c % 10 == 0) echo  '<div>';
    echo $resultado->id;
    if ($c % 10 == 0) echo  '</div>';

    $c++;
}
    
06.09.2018 / 13:58