FPDF with php and mysql
Posted: Wed Nov 26, 2008 9:19 pm
Hi Peeps,
Just wondering how to extract data from mysql into this fpdf code: here is my php code:
as you can see i have this echo to an html format, i understand i need to have:
however it will not retrieve the data. can sombody please help me out with this fpdf stuff.
Regards,
Justin
Just wondering how to extract data from mysql into this fpdf code: here is my php code:
Code: Select all
<?php
$title = $_POST ['title'];
$fName = $_POST['fName'];
$sName = $_POST ['sName'];
$address = $_POST ['address'];
$suburb = $_POST ['suburb'];
$state = $_POST ['state'];
$pCode = $_POST ['pCode'];
$homePh = $_POST ['homePh'];
$mobilePh = $_POST ['mobilePh'];
$make = $_POST ['make'];
$model = $_POST ['model'];
$pRange = $_POST ['pRange'];
$mWarranty = $_POST ['mWarranty'];
$wType = $_POST ['wType'];
$pPrice = $_POST ['pPrice'];
$salePrice = $_POST ['salePrice'];
$pDate = $_POST ['pDate'];
$sql = ("INSERT INTO customer (title, fName, sName, address, suburb, state, pCode, homePh, mobilePh, make, model, pRange, mWarranty, wType, pPrice, salePrice, pDate)
VALUES('$_POST[title]','$_POST[fName]','$_POST[sName]','$_POST[address]','$_POST[suburb]','$_POST[state]','$_POST[pCode]','$_POST[homePh]','$_POST[mobilePh]','$_POST[make]','$_POST[model]','$_POST[pRange]','$_POST[mWarranty]','$_POST[wType]','$_POST[pPrice]','$_POST[salePrice]','$_POST[pDate]')");
mysql_query($sql) or die ('error updating database');
$sql2 = mysql_query("SELECT * FROM customer ORDER BY certNum DESC LIMIT 0,1;")
or die(mysql_error());
if (mysql_num_rows($sql2) > 0) {
echo'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
echo'<html xmlns="http://www.w3.org/1999/xhtml">';
echo'<head>';
echo'<link href="stylesheet.css" rel="stylesheet" type="text/css" />';
echo'<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
echo'<title>Extended Warranty</title>';
echo'</head>';
echo'<body>';
echo'<div id="page">';
echo'<div id="header">';
echo'<a href="./index.html" class="logo"></a>';
echo'</div>';
echo'<div id="menulinks">';
echo'<?PHP include "includes/links.php"; ?>';
echo'</div>';
echo'<div id="mainarea">';
echo'<div id="contentarea"><table>';
echo'<tr>';
echo'<td width="282" valign="top"> <div id="sidebar">';
echo'</div></td>';
echo'<td width="657"><h2>Extended Warranty Invoice</h2>';
echo '<table cellpadding="3">';
while ($row = mysql_fetch_assoc($sql2)) {
echo"<tr><td><strong>Certificate Number:</strong></td><td>{$row['certNum']}</td><td><strong>Date of Purchase</strong><td>{$row['wDate']}</td></tr>";
echo"<tr><td><strong>Name:</strong></td><td>{$row['title']}{$row['fName']}{$row['sName']}</td></tr>";
echo"<tr><td><strong>Address:</strong></td><td>{$row['address']}</td></tr>";
echo"<tr><td><strong>Suburb:</strong></td><td>{$row['suburb']}</td></tr>";
echo"<tr><td><strong>State:</strong></td><td>{$row['state']}</td></tr>";
echo"<tr><td><strong>Post Code:</strong></td><td>{$row['pCode']}</td></tr>";
echo"<tr><td><strong>Home Phone Number:</strong></td><td>{$row['homePh']}</td></tr>";
echo"<tr><td><strong>Mobile Phone Number:</strong></td><td>{$row['mobilePh']}</td></tr>";
echo"<tr><td><strong>Make:</strong></td><td>{$row['make']}</td></tr>";
echo"<tr><td><strong>Model:</strong></td><td>{$row['model']}</td></tr>";
echo"<tr><td><strong>Manufactures Warranty:</strong></td><td>{$row['mWarranty']}</td></tr>";
echo"<tr><td><strong>Extended Warranty:</strong></td><td>{$row['wType']}</td></tr>";
echo"<tr><td><strong>Product Price:</strong></td><td>{$row['pPrice']}</td></tr>";
echo"<tr><td><strong>Product Purchase Date:</strong></td><td>{$row['pDate']}</td></tr>";
echo"<tr><td><strong>Extended Warranty Charge Total:</strong></td><td>{$row['salePrice']}</td></tr>";
}
echo'</td>';
echo'</tr>';
echo '</table>';
echo '</table>';
echo'</div>';
echo'</div>';
echo'<div id="footer">';
echo'<?PHP include "includes/footer.php"; ?>';
echo'</div>';
echo'</div>';
echo'</body>';
echo'</html>';
}
else
echo 'No rows in selected table';
mysql_close($conn);
?>
Code: Select all
define('FPDF_FONTPATH','/home/www/testing/pdf/font/');
require('home/www/testing/pdf/fpdf.php');
class PDF extends FPDF {
//then something like:
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('value','U',16);
$pdf->Cell(70,10,'logo here');
$pdf->Cell(80,10,'VALUE');
$pdf->Ln(40);
$pdf->SetFont('Helvetica','',12);
$pdf->Cell(70,10,'Bill to:');
$pdf->Ln(10);
$pdf->Cell(70,10,'Fname');
$pdf->Output("invoice.pdf",false);
Regards,
Justin