Search code examples
phphtmlmysqlipage-break

how to generate two reports on every single a4 page using while loop in php


I am working on a form which can generate several reports on a single click. These reports maybe in the hundreds so what I need to do is print only two reports on every single a4 page and after that the loop should jump to another page to print more reports. I just know the simple while loop is there anyone who can help me on this?

here is just the simple while loop which i know

while($row = mysqli_fetch_assoc($result)){
/**the reports goes here**/

}

Solution

  • As I mention in comment, you need to combine two reports in a single div with css of page-break something like,

    $i = 0;
    while($row = mysqli_fetch_assoc($result)){
     if($i % 2 == 0){
          echo "<div style='page-break-after:always'>"; 
     }
     /**the reports goes here**/
     if($i % 2 != 0){
          echo "</div>"; // Close div taking two reports in it.
     }
     $i++;
    }