Kindly someone help me know how to limit sql rows to 1 and add a new fpdf page when the row limit is reached.
My code is here below.
<?php
//declare data source///////
//require('../reports/index.php');
require('../fpdf/fpdf.php');
class PDF extends FPDF
{
// Page header
function Header()
{
include_once '../Connections/users.php';
// calendar picker
$term = $_POST['term'];
$a=$_POST['from'];
$b=$_POST['to'];
//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 daterec FROM safety_obs where checkmate='$term' AND daterec BETWEEN'$a' AND '$b' ");
$result1=mysqli_fetch_assoc($results);
$sobdate=$result1['daterec'];
$results = mysqli_query($con,"SELECT recid FROM safety_obs where checkmate='$term' AND daterec BETWEEN'$a' AND '$b' ");
$result1=mysqli_fetch_assoc($results);
$sobrecid=$result1['recid'];
$results = mysqli_query($con,"SELECT checkmate FROM safety_obs where checkmate='$term' AND daterec BETWEEN'$a' AND '$b' ");
$result1=mysqli_fetch_assoc($results);
$sobcheckmate=$result1['checkmate'];
$results = mysqli_query($con,"SELECT fname FROM safety_obs where checkmate='$term' AND daterec BETWEEN'$a' AND '$b' ");
$result1=mysqli_fetch_assoc($results);
$sobstaff=$result1['fname'];
$results = mysqli_query($con,"SELECT driver_name FROM safety_obs where checkmate='$term' AND daterec BETWEEN'$a' AND '$b' ");
$result1=mysqli_fetch_assoc($results);
$sobsreportee=$result1['driver_name'];
$results = mysqli_query($con,"SELECT client FROM safety_obs where checkmate='$term' AND daterec BETWEEN'$a' AND '$b' ");
$result1=mysqli_fetch_assoc($results);
$sobsclient=$result1['client'];
$results = mysqli_query($con,"SELECT sob_cat FROM safety_obs where checkmate='$term' AND daterec BETWEEN'$a' AND '$b' ");
$result1=mysqli_fetch_assoc($results);
$sobstype=$result1['sob_cat'];
$results = mysqli_query($con,"SELECT location FROM safety_obs where checkmate='$term' AND daterec BETWEEN'$a' AND '$b' ");
$result1=mysqli_fetch_assoc($results);
$sobslocation=$result1['location'];
$results = mysqli_query($con,"SELECT time FROM safety_obs where checkmate='$term' AND daterec BETWEEN'$a' AND '$b' ");
$result1=mysqli_fetch_assoc($results);
$sobstime=$result1['time'];
$results = mysqli_query($con,"SELECT description FROM safety_obs where checkmate='$term' AND daterec BETWEEN'$a' AND '$b' ");
$result1=mysqli_fetch_assoc($results);
$sobsdescription=$result1['description'];
$results = mysqli_query($con,"SELECT action FROM safety_obs where checkmate='$term' AND daterec BETWEEN'$a' AND '$b' ");
$result1=mysqli_fetch_assoc($results);
$sobsaction=$result1['action'];
$results = mysqli_query($con,"SELECT learning FROM safety_obs where checkmate='$term' AND daterec BETWEEN'$a' AND '$b' ");
$result1=mysqli_fetch_assoc($results);
$sobslearning=$result1['learning'];
// 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,$sobdate,1,0,'C');
$this->Ln(15);
$this->SetFont('Arial','B',8);
$this->Cell(20,5,'CHECKPOINT:',0,0,'C');$this->Cell(30,5,$sobcheckmate,1,0,'R');
$this->Ln(15);
$this->SetFont('Arial','B',8);
$this->Cell(20,5,'REF ID:',0,0,'C');$this->Cell(40,5,$sobrecid,1,0,'L');
$this->SetFont('Arial','B',8);
$this->Cell(20,5,'STAFF:',0,0,'C');$this->Cell(30,5,$sobstaff,1,0,'L');
$this->Ln(15);
$this->SetFont('Arial','B',8);
$this->Cell(20,5,'Reported By:',0,0,'C');$this->Cell(20,5,$sobsreportee,0,0,'L');
$this->Ln(4);
$this->SetFont('Arial','B',8);
$this->Cell(20,5,'Company:',0,0,'L');$this->Cell(30,5,$sobsclient,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,$sobstype,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,$sobslocation,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,$sobstime,0,0,'L');
$this->Ln(10);
$this->SetFont('Arial','',8);
$this->Cell(50,5,'Incident Description:',0,0,'R');$this->multiCell(0,4,$sobsdescription,1);
$this->Ln(10);
$this->SetFont('Arial','',8);
$this->Cell(50,5,'Action:',0,0,'R');$this->multiCell(0,4,$sobsaction,1);
$this->Ln(10);
$this->SetFont('Arial','',8);
$this->Cell(50,5,'Learning:',0,0,'R');$this->multiCell(0,4,$sobslearning,1);
$this->Ln(20);
$this->Ln(9);
$this->SetFont('Arial','U',8);
$this->Cell(180,5,'"----------------------------PLAN FOR SAFETY--------------------------"',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,' CHECKPOINT OFFICES::',0,0,'C');
$this->Ln(7);
$this->Cell(180,10,' Mxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,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);
$pdf->SetAutoPageBreak(false);
$filename=$_POST['term'];
$suffx='::Safety Observation Report.pdf';
$a=$_POST['from'];
$b=$_POST['to'];
//$nday=date('d-m-y');
$pdf->Output('D',$filename.'_'.$a.$suffx);
?>