FETCHING MYSQL ROWS AND PRINT TO EACH PDF PAGE

Kindly someone ammend the below code for me so that it fetches the datarows frommy sql table and print each record on its own pdf page. I have challenge to looping it and adding new page for new row

[php]<?php

//declare data source///////

//require(’…/reports/index.php’);
require(’…/fpdf/fpdf.php’);

class PDF extends FPDF
{
// Page header
function Header()
{

include_once ‘…/Conx/ewr.php’;
// calendar picker
$term = $_POST[‘term’];
$a=$_POST[‘from’];
$b=$_POST[‘to’];
//$pagecount = $pdf->setSourceFile(“pdfcard/pdfs/3Cards.pdf”);
//client
//$results = mysqli_query($con,“SELECT client FROM summary where client=’$term’”);
//$result1=mysqli_fetch_assoc($results);
//$client=$result1[‘client’];
//client
$results = mysqli_query($con,"SELECT * FROM safety_obs where checkmate=’$term’ AND daterec BETWEEN’$a’ AND ‘$b’ ");
//$result1=mysqli_fetch_array($results);
$result1 = mysqli_num_rows($results);

// Logo
$this->Image(’…/logo.jpg’,2,5,200);
$this->Ln(40);
// Arial bold 15
$this->SetFont(‘Arial’,‘B’,10);
// Move to the right
$this->Cell(6);
// Title
$this->Cell(150,7,‘CHECKMATE CHECKPOINTS SAFETY OBSERVATIONS REPORT’,1,0,‘C’);
$this->SetFont(‘Arial’,’’,8);
$this->Cell(10,5,‘DATE:’,0,0,‘C’);$this->Cell(30,5,$row[“daterec”],1,0,‘C’);
$this->Ln(15);
$this->SetFont(‘Arial’,‘B’,8);
$this->Cell(20,5,‘CHECKPOINT:’,0,0,‘C’);$this->Cell(30,5,$row[“checkmate”],1,0,‘R’);
$this->Ln(15);
$this->SetFont(‘Arial’,‘B’,8);
$this->Cell(20,5,‘REF ID:’,0,0,‘C’);$this->Cell(40,5,$row[“recid”],1,0,‘L’);

$this->SetFont('Arial','B',8);	
$this->Cell(20,5,'STAFF:',0,0,'C');$this->Cell(30,5,$row["fname"],1,0,'L');

$this->Ln(15);

$this->SetFont('Arial','B',8);	
$this->Cell(20,5,'Reported By:',0,0,'C');$this->Cell(20,5,$row["driver_name"],0,0,'L');

$this->Ln(4);

$this->SetFont('Arial','B',8);	
$this->Cell(20,5,'Company:',0,0,'L');$this->Cell(30,5,$row["client"],0,0,'L');

$this->Ln(4);

$this->SetFont('Arial','B',8);	
$this->Cell(50,5,'Safety Observation Type:',0,0,'L');$this->Cell(50,5,$row["sob_cat"],0,0,'L');

$this->Ln(4);

$this->SetFont('Arial','B',8);	
$this->Cell(50,5,'Location of Incident:',0,0,'L');$this->Cell(50,5,$row["location"],0,0,'L');

$this->Ln(4);
$this->SetFont(‘Arial’,‘B’,8);
$this->Cell(50,5,‘Time of Incident Happening:’,0,0,‘L’);$this->Cell(50,5,$row[“time”],0,0,‘L’);
$this->Ln(10);

	$this->SetFont('Arial','',8);	
$this->Cell(50,5,'Incident Description:',0,0,'R');$this->multiCell(0,4,$row["description"],1);

$this->Ln(10);

		$this->SetFont('Arial','',8);	
$this->Cell(50,5,'Action:',0,0,'R');$this->multiCell(0,4,$row["action"],1);

$this->Ln(10);

$this->SetFont('Arial','',8);	
$this->Cell(50,5,'Learning:',0,0,'R');$this->multiCell(0,4,$row["learning"],1);

$this->Ln(50);

$this->Ln(9);
$this->SetFont(‘Arial’,‘U’,8);
$this->Cell(180,5,’"--------------------------------------------------"’,0,0,‘C’);
}

// Page footer
function Footer()
{
// Position at 1.5 cm from bottom
$this->SetY(-40);
// Title
$this->Cell(25);
$this->SetFont(‘Arial’,’’,8);
$this->Cell(150,10,’ :’,0,0,‘C’);
$this->Ln(7);
$this->Cell(180,10,’ …’,1,0,‘C’);
$this->Ln(20);
// Arial italic 8
$this->SetFont(‘Arial’,‘I’,8);

// Page number
$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');

}
}}

// Instanciation of inherited class
$pdf = new PDF();
$pdf->AliasNbPages();
$pdf->AddPage(‘A4’);
$pdf->SetFont(‘Times’,’’,12);

$filename=$_POST[‘term’];
$suffx=’::Saf.pdf’;
$a=$_POST[‘from’];
$b=$POST[‘to’];
//$nday=date(‘d-m-y’);
$pdf->Output(‘D’,$filename.’
’.$a.$suffx);
?>[/php]

We are not a code service. Where are you having difficulty?

how to fetch mysql rows and while rows !=0,a pdf page is generated for each row dara

https://www.w3schools.com/Php/func_mysqli_fetch_array.asp

Sponsor our Newsletter | Privacy Policy | Terms of Service