Printing mailing labels - php, MySQL, FPDF
I'm having trouble getting this script to output a pdf for mailing labels. It throws this error: Parse error: syntax error, unexpected $end
<?php
define('FPDF_FONTPATH','/home/directory/public_html/sub/font/');
require_once('fpdf.php');
//Connect to your database
mysql_connect("localhost", "db_user","db_pw") or
die ("Could not connect to database");
mysql_select_db("database_name") or
die ("Could not select database");
$query = "SELECT employee_name, street_address, City, state, zip_code FROM employees ORDER BY `employee_nam开发者_StackOverflow社区e` ";
$result = mysql_query($query) or die('Error, query failed');
$num_rows = mysql_num_rows($result);
function PrintAddressLabels($result){
$pdf=new FPDF();
$pdf->Open();
$pdf->AddPage();
$pdf->SetFont('Arial','B',14);
$pdf->SetMargins(0,0);
$pdf->SetAutoPageBreak(false);
$x = 0;
$y = 0;
$i=0;
while (TRUE) {
if ($row=$result[$i]) {
//positions set above
$LabelText = sprintf("%s\n%s %s\n%s, %s, %s",
$row['employee_name'],
$row['street_address'],
$row['City'],
$row['state'],
$row['zip_code']);
Avery5160($x,$y,&$pdf,$LabelText);
$y++; // next row
if ($y == 10 ) { // end of page wrap to next column
$x++;
$y = 0;
if ($x == 3 ) { // end of page
$x = 0;
$y = 0;
$pdf->AddPage();
}
}
$i++; //counter through result
} else {
// Error quit printing
break;
}
{
$pdf->Output('mailing_labels.pdf','D');
}
?>
Right before you output the pdf, you have a {
which should be }
.
I've formatted the code you posted so that blocks are indented. This makes it easier to se where you might be missing a }
.
You appear to be missing the matching }
for your while()
. Or your function..
精彩评论