php - Page Break After Specific Number Of Rows -
i developing voucher printing application prints serial numbers , pins mysql table , displays them in page.
the php code displays 2 records per row..with being in separate column i.e 2 columns displayed side side due format of page (two records per row)..i can not display each record in seperate table. rather records contained in "general" table.
the voucher printing requires 2 rows displayed on each page.
i implemented "page-break-after: always" style each row not divisble two, page break not showing. code shown below:
$aray=array(); while($row=mysqli_fetch_array($sql_res)) { $aray[]=$row; } $nr_elm=count($aray); $table='<table width=100%><tr>'; $nr_col=2; if($nr_elm>0) { $p=1;//this row counter for($i=0;$i<$nr_elm;$i++) { $table.='<td><div style="border: 2px dashed #000;" ><div id="image" style="float:left;"> '.$p.' <img src="crswb1.png" height=80 width=60 /> </div><div id="texts" style=" float: none; margin-left:60px;"> <p> amount:'.$aray[$i]['amount'].' </p><p> pin:17263648409</p><p> serial:5374748548 </div></div></td>'; $col_to_add=($i+1)%$nr_col; if($col_to_add==0) { if($p % 2 == 0) { $table.="<tr style='page-break-after:always'>"; } $table.='</tr><tr>'; $p++; } } } $table.='</tr></table>'; $table=str_replace('<tr></tr>','',$table); echo $table; ?> i viewed page source , "page break" style showing neccessary row, seen below
<tr style='page-break-after:always'></tr><tr><td><div style="border: 2px dashed #000;" ><div id="image" style="float:left;"> 3 <img src="crswb1.png" height=80 width=60 /> </div><div id="texts" style=" float: none; how can ensure page break displayed can print 2 rows per page?..thanks.
the format of page not prevent use 1 table every 2 values. e.g. use following html code:
<table id="table1"> <tr> <td>this cell no. 1 in table 1</td> <td>this cell no. 2 in table 1</td> </tr> </table> <table id="table1"> <tr> <td>this cell no. 1 in table 2</td> <td>this cell no. 2 in table 2</td> </tr> </table> together following css code:
@media print { table {page-break-after: always;} /* prevent blank page @ end */ table:last-of-type {page-break-after: auto;} } /* if want fields on 1 line */ table, tr { width: 100%; /* if fields still don't fit on 1 line * make font-size smaller */ font-size: 0.9em } it print 1 table per page. notice last table cause page-break. see work prepared codepen here. open codepen , try print page. should see every table on it's own page.
Comments
Post a Comment