簡體   English   中英

僅在打印時分頁

[英]Page break on print only

我正在制作一個 web 頁面來顯示來自 MySQL 數據庫的數據。 目前,其中一個表運行 86 行數據,我想打印前 50 行,然后分頁並打印帶有表頭的其余行,但我希望實際的 web 頁面顯示所有行休息,沒有表頭。

目前我正在使用'while'語句來計算打印的行數,而另一個'while'來讀取數據和

<div style="page-break-after: always"><span style="display: none;">&nbsp;</span></div>

打破頁面。 完整的代碼部分如下

 echo '<section>';
            echo '<h3>Spirits etc.</h3>';
            $lineCounter = 1; // Used for line counter
            $sql = "SELECT * FROM Spirit WHERE PAL = 'Y' ORDER BY Product";
            $result = mysqli_query($conn, $sql);
            $totalCounter = mysqli_num_rows($result);
            $totalCounter++;
            if (mysqli_num_rows($result) > 0) {
                echo '<table class="TFtable">';
                    echo '<tr>';
                        echo '<th>No.</th><th>Spirits etc.</th><th></th><th>Sulphites >10ppm</th><th>Phenylalanine</th><th>Caffeine<th>Dairy</th><th colspan=3>Cereals containing gluten</th>';
                    echo '</tr>';
                    while ($lineCounter < $totalCounter) {
                    
                        while($row = mysqli_fetch_assoc($result)) {
                            
                            if ( $row["None"] == 'None Known' ) {
                                echo '<tr>';
                                    echo '<td>' . $lineCounter .'</td>';
                                    echo '<td style="text-align:left">'.$row["Product"].'</td>';
                                    echo '<td colspan =8>'.$row["None"].'</td>';
                                echo '</tr>';
                                $lineCounter++;
                            } else {
                                echo '<tr>
                                    <td>' . $lineCounter . '</td>
                                    <td style="text-align:left">'.$row["Product"].'</td>
                                    <td>'.$row["None"].'</td>
                                    <td>'.$row["Sulphites"].'</td>
                                    <td>'.$row["Phenylalanine"].'</td>
                                    <td>'.$row["Caffeine"].'</td>
                                    <td>'.$row["Milk"].'</td>
                                    <td>'.$row["CCG_Barley"].'</td>
                                    <td>'.$row["CCG_Wheat"].'</td>
                                    <td>'.$row["CCG_Maize"].'</td>
                                </tr>';
                                $lineCounter++;
                            }
                            if ($lineCounter == 51 or $lineCounter == 101 or $lineCounter == 151 or $lineCounter == 201) {
                                echo '</table>';
                                echo '<div style="page-break-after: always"><span style="display: none;">&nbsp;</span></div>';
                                echo '<h4>Spirits etc. cont.</h4>';
                                echo '<table class="TFtable">';
                                echo '<tr>';
                                    echo '<th>No.</th><th>Spirts etc.</th><th></th><th>Sulphites >10ppm</th><th>Phenylalanine</th><th>Caffeine<th>Dairy</th><th colspan=3>Cereals containing gluten</th>';
                                echo '</tr>';
                            }
                        } 
                    } 
                    echo '</table>';
            } else {
                echo 'No spirit products';
            }
            echo '<div style="page-break-after: always"><span style="display: none;">&nbsp;</span></div>';
            echo '</section>'; 

您需要 CSS 和媒體查詢:

@media print {
  .print-page-break {
    page-break-after: always;
  }
}

然后使用class="print-page-break"而不是style="page-break-after: always"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM