0

I am using FPDF to tell teachers about over due books. The output displays a department, book number and last name. How can I force a page break when the department name changes.

The Problem: I need to access Department and do a test to see if the value is different from the previous one. I do not know how to access Department to do a test and if different innate a page break.

This a code segment:

class 
PDF extends PDF_MySQL_Table
{
function Header()
{
$currentDate = date("n/j/Y");

$this->SetFont('Arial','',18);
$this->Cell(0,6,'Over Due List',0,1,'C');
 $this->SetFont('Arial','',12);
$this->Cell(0,6,'(Title Left Out for Privacy)',0,1,'C');
 $this->SetFont('Arial','',12);
$this->Cell(0,6,  ' Date: ' .$currentDate,0,1,'C');
$this->Ln(10);
// Ensure table header is printed
parent::Header();
}
function Footer()
 {
// Position at 1.5 cm from bottom
$this->SetY(-15);
// Arial italic 8
$this->SetFont('Arial','I',8);
// Page number
$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');

}
}




$pdf = new PDF();
$pdf->AliasNbPages();
pdf->AddPage();

$pdf->AddCol('Department',40,'Department','C');
$pdf->AddCol('LastName',60,'Last Name','C');
$pdf->AddCol('bookid',20,'Material#','L');
$pdf->AddCol('loandate',25,'Due Date','C');
//------------
//********** 

$pdf->Table($link,"SELECT Mbook.BOOKNUM,
Mbook.TITLE,
Eloans.bookid,
Eloans.loandate,
Eloans.borroid,
people.Borronum,
people.FirstName,
people.LastName,
people.Department
FROM(
Mbook
INNER JOIN Eloans ON Mbook.BOOKNUM = Eloans.bookid
LEFT JOIN people ON Eloans.borroid = people.Borronum)
order by People.Department Desc");

$pdf->Output();
?>
Isaac Bennetch
  • 11,830
  • 2
  • 32
  • 43
  • I'd store the result of the previous query in a variable and test whether the current department is the same as the previous one. – Isaac Bennetch Oct 27 '18 at 15:29
  • That is what I would like to do but I can't seem to place the value of Department in a variable without getting an error. – user1218244 Oct 28 '18 at 17:04
  • Oh, I see - what is the error you're getting? – Isaac Bennetch Oct 29 '18 at 02:39
  • This is the segment where Department is retrieved from the table. while($row=mysqli_fetch_array($res)) $this->Row($row); How can I assign a variable to $row when it equals department? – user1218244 Oct 29 '18 at 12:35
  • So you're fetching the entire row in to an array, and need to parse that array to get the value out and in to a variable you can compare against (or copy the entire array, but I don't see any advantage to that). I prefer handling it as an associative array rather than numeric, in case the order changes, but this is pretty much up to personal preference. The PHP documentation at https://secure.php.net/manual/en/mysqli-result.fetch-array.php has a number of examples of doing this. – Isaac Bennetch Oct 29 '18 at 23:04
  • That should work. Thanks. – user1218244 Oct 30 '18 at 02:59

0 Answers0