fpdf/php中的分组报告
我试图用PHP和fpdf创建一个分组报告,但是我得到了重复的组,如附图所示。下面是我的代码fpdf/php中的分组报告,php,sql-server,fpdf,Php,Sql Server,Fpdf,我试图用PHP和fpdf创建一个分组报告,但是我得到了重复的组,如附图所示。下面是我的代码 $query = "SELECT ROW_NUMBER() OVER (ORDER BY Rentals.RentalId) row_num, CONVERT(varchar(24),RentalDate) as RentalDate, CustomerName, CustAddress, Telephone, DepositPaid, CONVERT(varchar(24),Star
$query = "SELECT ROW_NUMBER() OVER (ORDER BY Rentals.RentalId) row_num, CONVERT(varchar(24),RentalDate) as RentalDate,
CustomerName, CustAddress, Telephone, DepositPaid, CONVERT(varchar(24),StartDate) as StartDate, RentalStatus,
CONVERT(varchar(24),EndDate) as EndDate, ItemName, ItemUnit, CostPerUnit, ItemQty, RentalPeriod, ItemTotal, Rentals.RentalId
FROM Rentals, RentalDetls
WHERE Rentals.RentalId = RentalDetls.RentalId
AND RentalDate BETWEEN '$StartDate1' AND '$EndDate1'";
$result = sqlsrv_query($dbh, $query);
$pdf = new FPDF('L','mm','A4');
$pdf->AliasNbPages();
$pdf->AddPage('L');
$pdf->SetFont('helvetica','',14);
$pdf->Image('images/prog_logo.jpg',10,10,35);
$pdf->SetXY(50,10);
$pdf->Ln(1);
$pdf->SetXY(50,10);
$pdf->Cell(100,9, "{$CompanyName}",0,0, 'C',0);
$pdf->SetFont('helvetica','',10);
$pdf->SetXY(145,15);
$pdf->Cell(1,9, "{$PrintDate}",0,0, 'C',0);
$pdf->Cell(45,9, 'Tel:',0,0,'C',0);
$pdf->Cell(1,9, "{$CompanyPhone}",0,0, 'C',0);
$pdf->Ln(20);
$pdf->SetXY(50,15);
$pdf->SetFont('helvetica','',14);
$pdf->Cell(100,10, 'Renatl Service Details',0,0,'C',0);
$pdf->Line(5, 22, 290-5, 22);
$pdf->Ln(6);
$pdf->SetFont('helvetica','',12);
$pdf->Cell(120,10, 'Report Period: ',0,0,'C',0);
$pdf->SetX(85,10);
$pdf->Cell(15,10,"{$StartDate1}");
$pdf->SetX(109,10);
$pdf->Cell(10,10,'To');
$pdf->SetX(117,10);
$pdf->Cell(15,10,"{$EndDate1}");
$pdf->Ln(10);
$pdf->SetFont('Arial','',11);
while($res = sqlsrv_fetch_array($result))
{
$RentalId = $res['RentalId'];
$CustomerName = $res['CustomerName'];
$CustAddress = $res['CustAddress'];
$Telephone = $res['Telephone'];
$DepositPaid = $res['DepositPaid'];
$StartDate = $res['StartDate'];
$EndDate = $res['EndDate'];
$pdf->SetX(15,10);
$pdf->Cell(10,10,'Customer:');
$pdf->SetX(35,10);
$pdf->Cell(10,10,"{$CustomerName}");
$pdf->SetX(75,10);
$pdf->Cell(10,10,'Address:');
$pdf->SetX(90,10);
$pdf->Cell(10,10,"{$CustAddress}");
$pdf->SetX(140,10);
$pdf->Cell(10,10,'Telephone:');
$pdf->SetX(160,10);
$pdf->Cell(10,10,"{$Telephone}");
$pdf->SetX(190,10);
$pdf->Cell(10,10,'Deposit Paid:');
$pdf->SetX(215,10);
$pdf->Cell(10,10,"{$DepositPaid}");
$pdf->Ln(7);
$startY = $pdf->GetY();
$pdf->Line(15, $startY, 230, $startY);
$query9 = "SELECT ROW_NUMBER() OVER (ORDER BY RentalDetlsId) row_num, ItemName, ItemUnit, CostPerUnit, ItemQty,
RentalPeriod, ItemTotal
FROM RentalDetls
WHERE RentalId = '$RentalId'";
$result9 = sqlsrv_query($dbh, $query9);
while($res = sqlsrv_fetch_array($result9))
{
$row_num = $res['row_num'];
$ItemName = $res['ItemName'];
$ItemUnit = $res['ItemUnit'];
$CostPerUnit = $res['CostPerUnit'];
$ItemQty = $res['ItemQty'];
$RentalPeriod = $res['RentalPeriod'];
$ItemTotal = $res['ItemTotal'];
$pdf->SetX(25,10);
$pdf->Cell(5,10,"{$row_num}");
$pdf->SetX(35,10);
$pdf->Cell(5,10,"{$ItemName}");
$pdf->SetX(95,10);
$pdf->Cell(10,10,"{$ItemUnit}");
$pdf->SetX(120,10);
$pdf->Cell(65,10,"{$ItemQty}");
$pdf->SetX(140,10);
$pdf->Cell(15,10,number_format("{$CostPerUnit}",2),0,0,'R');
$pdf->SetX(170,10);
$pdf->Cell(15,10,"{$RentalPeriod}");
$pdf->SetX(185,10);
$pdf->Cell(15,10,number_format("{$ItemTotal}",2),0,0,'R');
$pdf->Ln(5);
}
$pdf->Ln(5);
}
请不要将图像用于代码、数据或错误。使用格式化文本。不知道,但是您有SQL注入问题