2012-07-22 56 views
0

我在使用php和fpdf時遇到了一些麻煩。如何在pdf中通過php和fpdf實現多列

我必須通過fpdf和php來製作PDF格式的報告,其中我想向學生展示一位老師正在教授的內容。

我想要的是,fpdf應該創建一個頁面與多欄相同的字段。知情同意的

鏈接:http://i1267.photobucket.com/albums/jj552/ThePerfectH/abc.png

這個形象,你可以看到在

,我想直到30的數據,一列之後,它應該在一個頁面中不同的列移動。

示例代碼:

$result=mysql_query("select p.p_sname as pap from sgm, students st 
    left join sps on st.studentid=sps.studentid 
    left join papers p on p.p_id=sps.paperid where p.type='optional' and 
    sgm.studentid=st.studentid and sgm.groupid=3 and st.course=3 and 
    st.status='Regular' order by name"); 
    if($result === FALSE) 
{ 
die(mysql_error()); // better error handling 
} 
$i=0; 
$max=30; 
$s=1; 
$row_height = 6; 
$y_axis = 33 + $row_height; 
while($row = mysql_fetch_array($result)) 
{ 
//If the current row is the last one, create new page and print column title 
if ($i == $max) 
{ 
    $y_axis= 33 + $row_height; 
    $pdf->SetX(80); 
    $pdf->SetTextColor(153,0,102); 
    $pdf->SetFont('Arial','',10); 
     //print column titles for the current page 
    $pdf->SetY(33); 
    $pdf->SetX(80); 
    $pdf->Cell(20,6,'S No.',1,0,'C',1); 
    $pdf->SetY($y_axis); 
    $pdf->SetX(80); 
    $pdf->Cell(20,6,$s,1,0,'C',1); 
    $y_axis = $y_axis + $row_height; 
     $i = $i + 1; 
    $s=$s+1; 


} 

     $rollno=$row['rollno']; 
    $name=$row['name']; 
    $cat=$row['cat']; 
    $pap=$row['pap']; 
    $pdf->SetY($y_axis); 
    $pdf->SetX(48); 
    $pdf->SetFont('Arial','',10); 
    $pdf->Cell(20,6,$s,1,0,'C',1); 
    //Go to next row 
    $s=$s+1; 
    $y_axis = $y_axis + $row_height; 

     $i = $i + 1; }  

正如你可以在PIC中看到的,這是創建只有一個新列後,導致我行的重疊。

任何人都可以幫忙。

回答

0

我已經完成了將SetX更改爲x_axis的工作,當它達到30時,它將添加到x_axis中