#php #fpdf
#php #fpdf
Вопрос:
Я пробовал foreach
, функции и array_chunk
, но я просто не могу отобразить данные в 3 столбцах. Этот код выводит одну и ту же дату для всех трех столбцов. У меня есть полный отчет в формате PDF, но эту страницу нужно разбить на 3 массива и распечатать. Я удалил весь свой пример кода, поскольку ни один из них не работал. Я был бы признателен за какое-то направление в этом, спасибо.
<?php
require ('conn.php');
require ('lib/fpdf.php');
// account or item_code for practice -- will be getting from a GET statment
$item_code= 9999;
// query to get fields for top part of form
$info=mysqli_query($conn,"SELECT * FROM practice WHERE item_code = $item_code");
while($row=mysqli_fetch_array($info)){
$firstname = $row['firstname'];
$lastname = $row['lastname'];
$street = $row['street'];
$city = $row['city'];
$st = $row['st'];
$zip = $row['zip'];
$name = "{$row['lastname']}, {$row['firstname']} ";
$csz = "{$row['city']}, {$row['st']} {$row['zip']}";
}
class PDF extends FPDF
{
// Page header
function Header()
{
// Logo
// $this->Image('sample.png',10,6,30);
// Arial bold 15
$this->SetFont('Arial','B',15);
// Move to the right
$this->Cell(80);
// Title
$this->Cell(30,10,' ',0,0,'C');
// Line break
$this->Ln(1);
}
// Page footer
function Footer()
{
// Position at 1.5 cm from bottom
$this->SetY(-30);
$this->SetFont('Arial','I',16);
$this->Cell(0,10, 'Thank You!',0,0,'C');
$this->Ln(4);
$this->Ln(4);
// Arial italic 8
$this->SetFont('Arial','I',8);
$this->Cell(0,10, 'ADDRESS',0,0,'C');
$this->Ln(4);
$this->Cell(0,10, 'TAX ID 99-9999999 www..com',0,0,'C');
$this->Ln(4);
// Page number
$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
}
/*A4 width : 219mm*/
$pdf = new PDF('P','mm','A4');
$pdf->AliasNbPages();
$pdf->AddPage();
/*output the result*/
/*set font to arial, bold, 14pt*/
$pdf->SetFont('Arial','B',20);
$pdf->SetDrawColor(180,180,255);
/*Cell(width , height , text , border , end line , [align])*/
$pdf->Cell(50 ,10,'',0,1);
$pdf->Cell(50 ,10,'',0,1);
$pdf->Cell(71 ,10,'',0,0);
$pdf->Cell(59 ,5,'TITLE',0,0,'C');
$pdf->Cell(59 ,10,'',0,1);
$pdf->SetFont('Arial','B',15);
$pdf->Cell(200 ,5,'2020 LIST',0,0,'C');
$pdf->Cell(19 ,5,'',0,1);
$pdf->SetFont('Arial','B',15);
$pdf->Cell(130 ,5,'',0,0);
$pdf->Cell(59 ,5,'',0,0);
$pdf->SetFont('Arial','B',10);
$pdf->Cell(189 ,10,'',0,1);
$pdf->Cell(50 ,10,'',0,1);
$pdf->SetFont('Arial','B',15);
$pdf->Cell(15 ,5,'',0,0);
$pdf->Cell(30 ,5,$name ,0,0);
$pdf->Cell(56 ,5,'' ,0,0);
$pdf->Cell(59 ,5,'',0,0);
$pdf->Cell(59 ,5,'',0,1);
$pdf->SetFont('Arial','',10);
$pdf->Cell(15 ,5,'',0,0);
$pdf->Cell(115 ,5,$street,0,0);
$pdf->Cell(25 ,5,' Account ID:',0,0);
$pdf->Cell(34 ,5,$item_code,0,1);
$pdf->Cell(15 ,5,'',0,0);
$pdf->Cell(115 ,5,$csz,0,0);
$pdf->Cell(59 ,5,'Any Questions Contact: Don',0,1);
$pdf->Cell(130 ,5,'',0,0);
$pdf->Cell(58 ,5,'don@.org',0,0);
$pdf->Cell(1 ,5,'',0,1);
$pdf->Cell(50 ,10,'',0,1);
$pdf->Cell(1 ,6,'_',0,0,'C');
$pdf->Cell(190,6,'',0,0,'C');
$pdf->Cell(2 ,10,'_',0,1);
$pdf->SetFont('Arial','B',15);
$pdf->Cell(15 ,6,'',0,0,'C');
$pdf->Cell(130 ,5,'Contributions',0,0);
$pdf->Cell(59 ,5,'',0,0);
$pdf->SetFont('Arial','B',10);
$pdf->Cell(189 ,10,'',0,1);
$pdf->Cell(100,10,'Check List',0,1);
$pdf->SetFillColor(180,180,255);
$pdf->SetDrawColor(180,180,255);
// $pdf->Cell(10,5,'',1,0);
$pdf->Cell(15,5,'Date',1,0);
$pdf->Cell(25,5,'Ckno',1,0);
$pdf->Cell(17,5,'Amt',1,0,'R');
$pdf->Cell(10,5,'',1,0);
$pdf->Cell(15,5,'Date',1,0);
$pdf->Cell(25,5,'Ckno',1,0);
$pdf->Cell(17,5,'Amt',1,0,'R');
$pdf->Cell(10,5,'',1,0);
$pdf->Cell(15,5,'Date',1,0);
$pdf->Cell(25,5,'Ckno',1,0);
$pdf->Cell(17,5,'Amt',1,1,'R');
$query=mysqli_query($conn, "SELECT * FROM practice WHERE item_code = $item_code ORDER BY item_date ASC");
while($data=mysqli_fetch_array($query)){
$odate=$data['item_date'];
$date = date("m-d", strtotime($odate));
//$pdf->Cell(10,5,'','LR',0);
$pdf->Cell(15,5,$date,'LR',0);
$pdf->Cell(25,5,$data['item_desc'],'LR',0);
$pdf->Cell(17,5,$data['order_item_price'],'LR',0,'R');
$pdf->Cell(10,5,'',0,0);
$pdf->Cell(15,5,$date,'LR',0);
$pdf->Cell(25,5,$data['item_desc'],'LR',0);
$pdf->Cell(17,5,$data['order_item_price'],'LR',0,'R');
$pdf->Cell(10,5,'',0,0);
$pdf->Cell(15,5,$date,'LR',0);
$pdf->Cell(25,5,$data['item_desc'],'LR',0);
$pdf->Cell(17,5,$data['order_item_price'],'LR',1,'R');
}
$pdf->Output();
?>
Комментарии:
1. Вы используете одну и ту же переменную
$data
во всех 3 столбцах. Просто измените это.2. почему вы не используете пакет-оболочку fpdi с вашим fpdf? это будет намного проще с меньшим количеством кода. Просто найдите «fpdi fpdf». Бесплатный пакет от Setasign работает нормально