我想根據“where $bulan”呼叫資料,在資料庫中 $bulan 有一些相同的資料,但如果我呼叫只顯示第一個輸入。我已經使用了 while 但它不起作用
你們能幫忙嗎?
我有這樣的代碼
<?php
require_once("fpdf/fpdf.php");
require_once('koneksi.php');
$no = 1;
$bulan = $_POST['bulan'];
$data = mysqli_query($conn, "SELECT proses1.*, customer.nickname FROM proses1 inner join
customer on customer.id_cust = proses1.id_cust WHERE proses1.tgl = '$bulan'");
while ($row = mysqli_fetch_array($data)) {
$pdf = new FPDF('l','mm','A4');
// membuat halaman baru
$pdf -> AddPage();
$pdf -> SetFont('Times','B','10');
// judul
$pdf->Cell(15,10,'',0,0,'L');
$pdf->Cell(100,20,'PT Ganding Toolsindo',0,2,'L');
$pdf -> SetFont('Times','','12');
$pdf->Cell(260,10,'Rekap Proses 1',0,2,'C');
$pdf -> image('dist/img/gandingrbg.png',10,13,15,15 );
$pdf -> SetFont('Times','','10');
$pdf->Cell(230,10,'Periode Bulan :',0,0,'R');
$pdf->Cell(20,10,date('d-M-Y', strtotime($_POST['bulan'])),0,1,'R');
$pdf -> SetFont('Times','B','10');
$pdf->Cell(10,10,'No',1,0,'C');
$pdf->Cell(17,10,'CUST',1,0,'C');
$pdf->Cell(50,10,'Nama Part',1,0,'C');
$pdf->Cell(17,10,'Kode Part',1,0,'C');
$pdf->Cell(30,10,'Nama Proses',1,0,'C');
$pdf->Cell(40,10,'Quantity Masuk',1,0,'C');
$pdf->Cell(45,10,'Quantity Not Good',1,0,'C');
$pdf->Cell(30,10,'Keterangan',1,0,'C');
$pdf->Cell(40,10,'Tanggal Dikerjakan',1,1,'C');
$pdf -> SetFont('Times','','10');
$pdf->Cell(10,10,$no ,1,0,'C');
$pdf->Cell(17,10,$row['nickname'],1,0,'C');
$pdf->Cell(50,10,$row['nama_part'],1,0,'C');
$pdf->Cell(17,10,$row['kode_part'],1,0,'C');
$pdf->Cell(30,10,$row['nama_proses'],1,0,'C');
$pdf->Cell(40,10,$row['qty_aktual'],1,0,'C');
$pdf->Cell(45,10,$row['qty_ng'],1,0,'C');
$pdf->Cell(30,10,$row['keterangan'],1,0,'C');
$pdf->Cell(40,10,$row['tgl'],1,1,'C');
$pdf->Output();
}
uj5u.com熱心網友回復:
(A) 請將以下幾行移出您的 while 回圈:
- $pdf = new FPDF('l','mm','A4');
- $pdf->輸出();
(B) 請同時添加 $pdf->Open(); 在上述(1)之后
[注意: 1.8x 或更高版本not需要此點 (B) ...]new versions
new FPDF 用于創建 FDPF 類的新物件,對于同一個物件實體不應該重復和重復;應該在創建整個 PDF 檔案后觸發輸出行(所以在 while 回圈之外)
所以改變(為了清楚起見,我從塊中洗掉了一些行):
while ($row = mysqli_fetch_array($data)) {
$pdf = new FPDF('l','mm','A4');
// membuat halaman baru
$pdf -> AddPage();
$pdf -> SetFont('Times','B','10');
// judul
$pdf->Cell(15,10,'',0,0,'L');
$pdf->Cell(100,20,'PT Ganding Toolsindo',0,2,'L');
// other lines for output omitted for clarity
$pdf->Cell(30,10,$row['keterangan'],1,0,'C');
$pdf->Cell(40,10,$row['tgl'],1,1,'C');
$pdf->Output();
}
至(樣本 1)
$pdf = new FPDF('l','mm','A4');
$pdf->Open();
// the above line is not needed for newer versions of FPDF (e.g. v1.8x)
while ($row = mysqli_fetch_array($data)) {
// membuat halaman baru
$pdf -> AddPage();
$pdf -> SetFont('Times','B','10');
// judul
$pdf->Cell(15,10,'',0,0,'L');
$pdf->Cell(100,20,'PT Ganding Toolsindo',0,2,'L');
// other lines for output omitted for clarity
$pdf->Cell(30,10,$row['keterangan'],1,0,'C');
$pdf->Cell(40,10,$row['tgl'],1,1,'C');
}
$pdf->Output();
(樣本 2)
如果要在一頁中顯示所有資料,請移動 $pdf -> AddPage(); 遠離回圈并將其放在new陳述句下
沙盒:
http://www.createchhk.com/SOanswers/sub8/testSO26Oct2022c.php
代碼:
$pdf = new FPDF('l','mm','A4');
$pdf -> AddPage();
$pdf->Open();
// the above line is not needed for newer versions of FPDF (e.g. v1.8x)
while ($row = mysqli_fetch_array($data)) {
// membuat halaman baru
$pdf -> SetFont('Times','B','10');
// judul
$pdf->Cell(15,10,'',0,0,'L');
$pdf->Cell(100,20,'PT Ganding Toolsindo',0,2,'L');
// other lines for output omitted for clarity
$pdf->Cell(30,10,$row['keterangan'],1,0,'C');
$pdf->Cell(40,10,$row['tgl'],1,1,'C');
}
$pdf->Output();
另一方面,正如其他人所建議的,請將您的查詢更改為引數化準備好的陳述句以避免 SQL 注入。詳情可參考以下內容:
https://www.php.net/manual/en/mysqli.quickstart.prepared-statements.php
沙盒鏈接
您可以嘗試以下沙箱來查看示例的效果(db 中的 3 條記錄,顯示兩個欄位):
http://www.createchhk.com/SOanswers/sub7/testSO26Oct2022.php
(對于較新的版本,例如 FPDF 1.8x): http ://www.createchhk.com/SOanswers/sub8/testSO26Oct2022b.php
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/519449.html
標籤:phppdf格式
上一篇:PHPPDOREPLACE在phpadmin中有效,但在php中無效
下一篇:輪播滑塊垂直而不是水平加載專案
