Skip to content Skip to sidebar Skip to footer

Php Code To Break Page After 6th Row

I try to display 2 table side by side with php code.... but i need to display only 6 table on single page ......and rest on another page...... so plz can any one help me to break p

Solution 1:

Try using CSS:

<style>
@media print {
    .pageBreak {
        page-break-after: always;
    }
}
</style>

And at every 6 table, add a pageBreak:

<?php
$lineCounter = 0;
if (is_array($data)) {
    foreach($data as $row) {
        $lineCounter++;
?>

<!-- output a table... -->

<?php
        if($lineCounter % 6 == 0) {
            echo '<span class="pageBreak"></span>' . PHP_EOL;
        }
    }
}
?>

Solution 2:

try this is code or visit link

    <?php 
    $q = "SELECT * FROM your_table ";
    $myq = mysqli_query($link, $q);
    $fixtures ='';
    $i=0;
        while($row=mysqli_fetch_assoc($myq)) {
            $r[]=$row;
        }

        foreach ($r as $val) {
            $i++;
    ?>
    <!-- your value from database -->
    <table>
        <tr>
            <td><?php echo $val['your_column']; ?></td>
        </tr>
    </table>
    <!-- your value from database -->
    <?php
            if($i % 6==0){
                echo '<div style="page-break-after: always;">[------ break ------]</div>' . PHP_EOL;
            $i=0;
            }
        }

    ?>

Post a Comment for "Php Code To Break Page After 6th Row"