Included is my code for displaying in pdf format data from 2 fields in 119 records. I can get the data to display in one long column spread over 3 pages. I want to display the data on 1 page over several columns. I’m stuck; don’t know how to proceed.
<?php
require('fpdf.php');
require('connection.php');
class PDF extends FPDF
{
// Page header
function Header()
{
}
// Page footer
function Footer()
{
// Position at 2.5 cm from bottom
$this->SetY(-25);
//Arial italic 8
$this->SetFont('Arial','',8);
//Page number
$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
}
$pdf = new PDF();
$pdf->AddPage('P','A4');
// Necessary for x of y page numbers to appear in document
$pdf->AliasNbPages();
$pdf->SetAutoPageBreak(false);
// Document properties
$pdf->SetFont('Arial','U',14);
$pdf->Cell(40,10,'Class Counts');
// Add date report run
$pdf->SetFont('Arial','',10);
$pdf->Setx(10);
$pdf->Sety(5);
$date = date("F j, Y");
$pdf->Cell(40,30,'Report date: '.$date);
$pdf->SetDrawColor(0, 0, 0); //black
// Table header
$pdf->SetFillColor(170, 170, 170); //gray
$pdf->setFont("Arial","","10");
$pdf->setXY(10, 29.5);
// Field names
$pdf->Cell(11, 5, "CLS", 1, 0, "C", 1);
$pdf->Cell(11, 5, "CNT", 1, 0, "C", 1);
$y = 35;
$x = 10;
$pdf->setXY($x, $y);
// Configure connection script
$query="SELECT * FROM class_counts ORDER BY `Class` ASC LIMIT 0, 500 ";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$total_count = 0;
while($row = mysql_fetch_array($result))
{
// Field data
$pdf->SetFillColor(198, 245, 175);
$pdf->setFont("Arial","","8");
$pdf->Cell(11, 5, $row['Class'], '', '','C', 1);
$pdf->Cell(11, 5, $row['Count'], '', '','C', 1);
$y += 5.5;
// If page break needed
if ($y > 275)
{
$pdf->AddPage('P','A4');
$y = 10;
}
$pdf->setXY($x, $y);
// Total entries
$total_count += $row['Count'];
}
$pdf->SetX(23);
$pdf->setFont("Arial","B","10");
$pdf->Cell(40,15,"$total_count".' entries','','','L');
$pdf->Output();