Skip Page of 5 in 5 Blocks

1

Good afternoon,

I'm returning data from a table and showing it in CSS, however I need to display 5 blocks per page and every 5 blocks I need to insert a piece of code to force the browser to go to another page.

Example:

while($row = mysql_fetch_array($busca)){
echo "<div class='bloco'>
<p class'nome'>FULANO</p>
<address>Endereço</addess>  
</div>";    
}

I would like that when I show 5 blocks, I can insert this line below

<div style="page-break-before: always !important"></div>
    
asked by anonymous 18.07.2015 / 17:40

1 answer

2

You can increment a counter and check if it is a multiple of 5 at each loop.

$i=1;
while($row = mysql_fetch_array($busca)){
    echo "<div class='bloco'>
    <p class'nome'>FULANO</p>
    <address>Endereço</addess>  
    </div>";
    if($i % 5 === 0) echo '<div style="page-break-before: always !important"></div>';    
    $i++;
}
    
18.07.2015 / 19:38