2017-07-21 2 views
0

Ich muss PDF-Seite basierend auf PHP foreach Ergebnis generieren und 2 Spalten anzeigen (A4 PDF Landscape-Modus). Für z.B. Daten wie folgt aussehen:PHP foreach Zeilen zu 2 Spalte

Row data 1 
Row data 2 
Row data 3 
Row data 4 
Row data 5 
Row data 6 

, wenn die Höhe in PDF Spalte 1 (HTML-Tabelle) überschreitet, wird es auf der 2. Spalte der Seite bewegen und es sieht so aus:

Row data 1 Row data 7 
    Row data 2 Row data 8 
    Row data 3 Row data 9 
    Row data 4 
    Row data 5 
    Row data 6 

Mein Code:

<table width="100%" cellspacing="0" cellpadding="0" border="0"> 
    <thead> 
     <tr> 
      <th width="140px">Subject</th> 
      <th width="100px">Teacher</th> 
      <th width="8%">Exam</th> 
     </tr> 
    </thead> 
<tbody> 
<?php 
    foreach($data as $std) 
    { 
?> 
<tr> 
    <td><?php echo $std->data1; ?></td> 
    <td><?php echo $std->data2; ?></td> 
    <td><?php echo $std->data3; ?></td> 
</tr> 
<?php 
} 
?> 
</tbody> 
</table> 
+0

Also, was ist Ihre Frage? –

+0

was hast du vorher versucht? – user3663

Antwort

1

versuchen, wie diese

require('fpdf.php');//download fpdf and include 
$pdf = new FPDF(); 
$myarray = array(1,2,3); 
$pdf->SetFont('Arial','B',16); 
foreach($myarray as $value){ 
$pdf->AddPage(); 
$pdf->Cell(40,10,$value); 
} 
$pdf->Output() 
0

A4 ist tatsächlich Höhe: 297mm und Breite: 210mm für Web in Portrait folgen Sie diesem Link für mehr http://www.thecalculatorsite.com/forum/topics/width-and-height-a4-paper.php. Also für Landschaft wird es Höhe: 210mm und Breite: 297mm. Ich habe dir einen ungefähren Code für deinen Zweck gegeben. Ändern Sie die $ max_rows mit der Anzahl der Zeilen, die eine Seite enthalten kann, ohne zu brechen. Und style die height width -Eigenschaft der Tabelle, Spalten und Zeilen, um Ihre Bedürfnisse zu unterstützen.

<!DOCTYPE html> 
<html> 
    <head> 
     <style> 
     body { 
      height: 210mm; 
      width: 297mm; 
      /* to centre page on screen*/ 
      margin-left: auto; 
      margin-right: auto; 
     } 
     </style> 
    </head> 
    <body> 
    <table style="float:left;" width="50%" cellspacing="0" cellpadding="0" border="0"> 
     <thead> 
      <tr> 
       <th width="140px">Subject</th> 
       <th width="100px">Teacher</th> 
       <th width="8%">Exam</th> 
      </tr> 
     </thead> 
     <tbody> 
    <?php 
    $max_rows = 6; 
    $count_row = 0; 
    foreach($data as $std) 
    { 
     $count_row++; 
     if($count_row > $max_rows) 
      $count_row = 0; 

     if($count_row == 0) { 
    ?> 
     </tbody> 
    </table> 

    <table style="float:left;" width="50%" cellspacing="0" cellpadding="0" border="0"> 
     <thead> 
      <tr> 
       <th width="140px">Subject</th> 
       <th width="100px">Teacher</th> 
       <th width="8%">Exam</th> 
      </tr> 
     </thead> 
     <tbody> 
<?php } ?> 
      <tr> 
       <td><?php echo $std->data1; ?></td> 
       <td><?php echo $std->data2; ?></td> 
       <td><?php echo $std->data3; ?></td> 
      </tr> 
<?php 
} 
?> 
     </tbody> 
    </table> 
    </body> 
</html> 
+0

Es wird nach einer bestimmten Anzahl von Zeilen nicht in die zweite Spalte verschoben. –