Skip page 5 in 5 Blocks

Asked

Viewed 68 times

1

Good afternoon,

I’m returning data from a table and showing in CSS, but I need to display 5 blocks per page and every 5 blocks I need to insert a snippet 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 when it was shown 5 blocks, I can insert this line below

<div style="page-break-before: always !important"></div>

1 answer

2


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

$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++;
}
  • Just be careful with ifs without {}.

  • Managed to elaborate?

  • 1

    It worked friends, ball show! My first post here on the forum, used to use the Imasters, but there it is very still. Thanks!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.