if语句无法正常工作,它将正确打印一页,然后打印另外17页没有列标题和仅一个数据行。我一直无法弄清楚这种方式无法正常工作。有一个更好的方法吗。我正在做FPDF网站的休息处理。我的if语句无法正常工作
链接到一个PDF文件,以显示这是什么代码产生http://notaryaccounting.com/testpdf.pdf
$pdf = new PDF();
$pdf->AddPage ($orientation='', $format='', $keepmargins=false, $tocpage=false);
$pdf->SetPrintHeader(true);
$pdf->SetPrintFooter(true);
$pdf->setFontSubsetting(true);
// set margins
$pdf->SetMargins(10, PDF_MARGIN_TOP, 10);
$pdf->SetFont('Arial', 'BI', 20, '', 'false');
$year = date("Y"); ;
$html = 'Mileage for signing1 dates from 1/1/' .$year. ' to 12/31/' .$year. '';
$pdf->SetXY(2, 15);
$pdf->SetFont('times', '', 8, '', true);
$pdf->writeHTML ($html, $ln=true, $fill=false, $reseth=false, $cell=false, $align='R');
//set initial y axis position per page
$y_axis_initial = 20;
//print column titles
$pdf->SetFillColor(232,232,232);
$pdf->SetFont('Arial','B',12);
$pdf->SetY($y_axis_initial);
$pdf->SetX(10);
$pdf->Cell(20,6,'Invoice #:',1,0,'L',1);
$pdf->Cell(27,6,'Signing Date:',1,0,'L',1);
$pdf->Cell(30,6,'Name:',1,0,'L',1);
$pdf->Cell(60,6,'Location:',1,0,'L',1);
$pdf->Cell(15,6,'Start:',1,0,'L',1);
$pdf->Cell(15,6,'End:',1,0,'L',1);
$pdf->Cell(20,6,'Mileage:',1,0,'L',1);
//Go to next row
$y_axis = 26;
$y_axis = $y_axis + $row_height;
//initialize counter
$i = 0;
//Set maximum rows per page
$max = 25;
//Set Row Height
$row_height = 6;
$result = $db->query("SELECT invoicenumber,signstart,fname,lname,street1,city,state,mstart,mend FROM signings1 WHERE pid = $pid ORDER by signstart");
foreach($result as $key => $sig) {
$totalcont = $totalcont + 1;
echo $i;
//If the current row is the last one, create new page and print column title
if ($i == $max){
$pdf->AddPage();
//print column titles for the current page
$pdf->SetY($y_axis_initial);
$pdf->SetFillColor(232,232,232);
$pdf->SetFont('Arial','B',12);
$pdf->SetX(05);
$pdf->Cell(20,6,'Invoice #:',1,0,'L',1);
$pdf->Cell(27,6,'Signing Date:',1,0,'L',1);
$pdf->Cell(30,6,'Name:',1,0,'L',1);
$pdf->Cell(60,6,'Location:',1,0,'L',1);
$pdf->Cell(15,6,'Start:',1,0,'L',1);
$pdf->Cell(15,6,'End:',1,0,'L',1);
$pdf->Cell(20,6,'Mileage:',1,0,'L',1);
//Go to next row
$y_axis = $y_axis + $row_height;
//Set $i variable to 0 (first row)
$i = 0;
}
$invoicenumber = $sig[invoicenumber];
$signdate=phpdate($sig[signstart]);
$name = $sig[fname] . ' ' . $sig[lname];
$location = $sig[street1] . " " . $sig[city] . " " . $sig[state];
$mstart = $sig[mstart];
$mend = $sig[mend];
$miles = $sig[miles];
$miles1 = $mend - $mstart;
$subTotal += $miles1;
$totalmoney = $subTotal * .56;
$pdf->SetFont('Arial','B',9);
$pdf->SetFillColor(255,255,255);
$pdf->SetY($y_axis);
$pdf->SetX(10);
$pdf->Cell(20,6,$invoicenumber,1,0,'L',1);
$pdf->Cell(27,6,$signdate,1,0,'L',1);
$pdf->Cell(30,6,$name,1,0,'L',1);
$pdf->Cell(60,6,$location,1,0,'L',1);
$pdf->Cell(15,6,$mstart,1,0,'L',1);
$pdf->Cell(15,6,$mend,1,0,'L',1);
$pdf->Cell(20,6,$miles1,1,0,'L',1);
//Go to next row
$y_axis = $y_axis + $row_height;
$i = $i + 1;
}
ob_end_clean();
$pdf->Output();
我不是从移除错误除了触摸原始代码和检查分页符是否正常工作。我会去看看它,看看我能否理解它。我会以某种关于它的信息回复你。它可能是明天,因为它在这里傍晚。我之前没有玩过pdf输出,所以我正在学习新的东西。 –