Solved

PDF Labels using PHP

Posted on 2009-04-09
1
542 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

786 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