2017-06-16 91 views
0

我想在我的pdf中添加一个自动递增的序列号列。我试图从数据库中获取它,但由于检索的数据是随机的,因此印在PDF上的序列号也是随机的。我想开始它像1,2,3 ...FPDF-如何在列中提供自动递增的序列号?

$sql2 = "SELECT * FROM `" . $DB->pre . "order_detail` 
     WHERE orderID= '$orderID'"; 
$rows2 = $DB->dbRows($sql2); 

if ($DB->numRows > 0){ 

    $pdf->SetLineWidth(0); 
    $pdf->SetFont('Arial','',10); 
    $newL=110;   ////fixed cell spaced in y-axis for quantity 
    $cnt=0; 
    foreach ($rows2 as $d2) { 
     $rows2++; 
     $pdf->SetXY(11,$newL); 
     $pdf->Cell(11,7, ,1,0,'L',0); /////SERIAL NUMBER COLUMN///// 
     $pdf->SetXY(22,$newL); 
     $pdf->Cell(22,7,$d2['materialDesc'],1,0,'L',0); 
     $pdf->SetXY(44,$newL); 
     $pdf->Cell(15,7,$d2['chart'],1,0,'L',0); 
     $pdf->SetXY(59,$newL); 
     $pdf->Cell(25,7,$d2['shade'],1,0,'L',0); 
     $pdf->SetXY(84,$newL); 
     $pdf->Cell(18,7,$d2['materialSize'],1,0,'L',0); 
     $pdf->SetXY(102,$newL); 
     $pdf->Cell(25,7,$d2['quantity'],1,0,'L',0); 
     $pdf->SetXY(127,$newL); 
     $pdf->Cell(15,7,'ROL',1,0,'L',0); 
     $pdf->SetXY(142,$newL); 
     $pdf->Cell(18,7,'OPEN',1,0,'L',0); 
     $pdf->SetXY(160,$newL); 
     $pdf->Cell(35,7,$d2['remarks'],1,0,'L',0); 
     $newL += 7; 
    }  
} 
$pdf-> Ln(); 
+0

在SO的想法是,你编码的东西。如果您遇到问题,请向我们寻求帮助。我们不写你的代码给你 – RiggsFolly

+0

呃..我第一次使用FPDF,并且我找不到任何其他网站的帮助。我所要求的只是一个想法,而不是写出整个代码。你最好冲洗你的自我配偶。 –

+0

此报告的所有行上的序列号是否相同,或者此报告的每行上都是+1。你是否需要记住这个序列号,以便在你的下一次报告中,每行都可以是oldserial + 1。或者你会从每个报告 – RiggsFolly

回答

0

然后,你只需要一个计数器。

$sql2 = "SELECT * FROM `" . $DB->pre . "order_detail` 
     WHERE orderID= '$orderID'"; 
$rows2 = $DB->dbRows($sql2); 

if ($DB->numRows > 0){ 

    $pdf->SetLineWidth(0); 
    $pdf->SetFont('Arial','',10); 
    $newL=110;   ////fixed cell spaced in y-axis for quantity 

    // you already had a counter so I am reusing it 
    $cnt=1; 

    foreach ($rows2 as $d2) { 
     $rows2++; 
     $pdf->SetXY(11,$newL); 

     // place counter in column 
     $pdf->Cell(11,7, $cnt,1,0,'L',0); /////SERIAL NUMBER COLUMN///// 
     $pdf->SetXY(22,$newL); 
     $pdf->Cell(22,7,$d2['materialDesc'],1,0,'L',0); 
     $pdf->SetXY(44,$newL); 
     $pdf->Cell(15,7,$d2['chart'],1,0,'L',0); 
     $pdf->SetXY(59,$newL); 
     $pdf->Cell(25,7,$d2['shade'],1,0,'L',0); 
     $pdf->SetXY(84,$newL); 
     $pdf->Cell(18,7,$d2['materialSize'],1,0,'L',0); 
     $pdf->SetXY(102,$newL); 
     $pdf->Cell(25,7,$d2['quantity'],1,0,'L',0); 
     $pdf->SetXY(127,$newL); 
     $pdf->Cell(15,7,'ROL',1,0,'L',0); 
     $pdf->SetXY(142,$newL); 
     $pdf->Cell(18,7,'OPEN',1,0,'L',0); 
     $pdf->SetXY(160,$newL); 
     $pdf->Cell(35,7,$d2['remarks'],1,0,'L',0); 
     $newL += 7; 
     // add 1 to the counter 
     $cnt++; 
    }  
} 
$pdf-> Ln(); 
+0

非常感谢朋友。干杯。 –