Code:
<?php
require('fpdf.php');
class PDF extends FPDF
{
//Load data
function LoadData($file)
{
//Read file lines
$lines=file($file);
$data=array();
foreach($lines as $line)
$data[]=explode(';',chop($line));
return $data;
}
//Simple table
function BasicTable($header,$data)
{
//Header
foreach($header as $col)
$this->Cell(40,7,$col,1);
$this->Ln();
//Data
foreach($data as $row)
{
foreach($row as $col)
$this->Cell(40,6,$col,1);
$this->Ln();
}
}
//Better table
function ImprovedTable($header,$data)
{
//Column widths
$w=array(40,35,40,45);
//Header
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'C');
$this->Ln();
//Data
foreach($data as $row)
{
$this->Cell($w[0],6,$row[0],'LR');
$this->Cell($w[1],6,$row[1],'LR');
$this->Cell($w[2],6,number_format($row[2]),'LR',0,'R');
$this->Cell($w[3],6,number_format($row[3]),'LR',0,'R');
$this->Ln();
}
//Closure line
$this->Cell(array_sum($w),0,'','T');
}
//Colored table
function FancyTable($header,$data)
{
//Colors, line width and bold font
$this->SetFillColor(255,0,0);
$this->SetTextColor(255);
$this->SetDrawColor(128,0,0);
$this->SetLineWidth(.3);
$this->SetFont('','B');
//Header
$w=array(40,35,40,45);
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'C',1);
$this->Ln();
//Color and font restoration
$this->SetFillColor(224,235,255);
$this->SetTextColor(0);
$this->SetFont('');
//Data
$fill=0;
foreach($data as $row)
{
$this->Cell($w[0],6,$row[0],'LR',0,'L',$fill);
$this->Cell($w[1],6,$row[1],'LR',0,'L',$fill);
$this->Cell($w[2],6,number_format($row[2]),'LR',0,'R',$fill);
$this->Cell($w[3],6,number_format($row[3]),'LR',0,'R',$fill);
$this->Ln();
$fill=!$fill;
}
$this->Cell(array_sum($w),0,'','T');
}
}
$pdf=new PDF();
//Column titles
$header=array('Country','Capital','Area (sq km)','Pop. (thousands)');
//Data loading
$data=$pdf->LoadData('countries.txt');
$pdf->SetFont('Arial','',14);
$pdf->AddPage();
$pdf->BasicTable($header,$data);
$pdf->AddPage();
$pdf->ImprovedTable($header,$data);
$pdf->AddPage();
$pdf->FancyTable($header,$data);
$pdf->Output();
?>
and it outputs this:
Code:
$GetList2 = "SELECT * FROM internal_items WHERE order_id = $displayOrderID";
$ResultList2 = mysql_query($GetList2);
$items2 = mysql_num_rows($ResultList2);
while ($iitems2 < $items2) {
$itemID = mysql_result($ResultList2,$iitems2,"id");
$quantity = mysql_result($ResultList2,$iitems2,"quantity");
$unit_price = mysql_result($ResultList2,$iitems2,"unit_price");
$line_price = mysql_result($ResultList2,$iitems2,"line_price");
$description = mysql_result($ResultList2,$iitems2,"description");
$quantityHSC = stripslashes (htmlspecialchars ($quantity));
$unit_priceHSC = stripslashes (htmlspecialchars ($unit_price));
$descriptionHSC = stripslashes (htmlspecialchars ($description));
echo "<tr>\n";
echo "<td class=\"tableCell\" align=\"left\"><p class=\"tableCellText\">\n";
echo "$quantityHSC\n";
echo "</p></td>\n";
echo "<td class=\"tableCell\" align=\"left\"><p class=\"tableCellText\">\n";
echo "$descriptionHSC\n";
echo "</p></td>\n";
echo "<td class=\"tableCell\" align=\"left\"><p class=\"tableCellText\">\n";
$unit_priceDisplay = number_format($unit_priceHSC, 2);
echo "£$unit_priceDisplay\n";
echo "</p></td>\n";
echo "<td class=\"tableCell\" align=\"left\"><p class=\"tableCellText\">\n";
$line_priceDisplay = number_format($line_price, 2);
echo "£$line_priceDisplay\n";
echo "</p></td>\n";
echo "</tr>\n";
$iitems2++;
}
Bookmarks