Solved

PDF Labels using PHP

Posted on 2009-04-09
1
552 Views
Last Modified: 2013-12-13
Hello,

I am not an expert at PHP or MYSQL, but I have been able to piece together a PHP script to create a sheet of labels from a customer database.  I keep getting an error.


Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in F:\xampp\htdocs\labels.php on line 20

Warning: Cannot modify header information - headers already sent by (output started at F:\xampp\htdocs\PDF_label.php:182) in F:\xampp\htdocs\fpdf.php on line 1022
FPDF error: Some data has already been output to browser, can't send PDF file

Here is the Labels.php file.
Labels.php
 
<?php
 
if(!empty($_POST['labels']))
{
 
define('FPDF_FONTPATH','font/');
require_once('PDF_Label.php');
require('conn.php');
$labels = explode(',', $_POST['labels']);
 
$pdf = new PDF_Label('L7163', 'mm', 1, 2);
$pdf->Open();
$pdf->AddPage();
 
foreach($labels as $labelId)
{
$query = "SELECT CustomerID,FirstName,LastName,PhysAddress1,PhysAddress2,PhysTown,PhysState,PhysZip FROM customers
WHERE WSHave = 'ON'";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
 
for($i=1;$i<=40;$i++)
$pdf->Add_PDF_Label(sprintf("%s\n%s\n%s\n%s, %s, %s", $row['FirstName'], $row['LastName'], $row['PhysAddress1'], $row['PhysAddress2'], $row['PhysTown'], $row['PhysState'],$row['PhysZip'] ));
 
}
$pdf->Output();
 
}
?>
<form method="post" action="<?php echo $_SERVER['SCRIPT_NAME'];?>">
List ids separated by a comma: <input type="text" name="labels" /><br>
<input type="submit" value="Generate Labels" />
</form>

Open in new window

0
Comment
Question by:hydrazi
1 Comment
 
LVL 14

Accepted Solution

by:
shobinsun earned 500 total points
ID: 24113390
Hello,

"Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in F:\xampp\htdocs\labels.php on line 20"

Means that your sql query is not correct. Check the table fields. and use 'echo mysql_num_rows($result)' after the line:

$result = mysql_query($query);

You will get the exact number of rows.

Check that.

And for  labels in pdf using FPDF, I have given a good example about that in:

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/Q_24292268.html?cid=236#a24060272

Hope this will help you.

And 'FPDF error: Some data has already been output to browser, can't send PDF file'

Means that there is another output is generated before pdf output.

Please check that also.

Regards.

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question