473,372 Members | 1,310 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

address labels using php | mysql | fpdf

i'm looking for some script which would export address labels from a
mysql db to pdf ...

There's an exapmle, but i'm not able to convert it for using with
mysql ... can anybody help?

THX a lot

Martin :)
Author: Steve Dillon (208.241.182.---)
Date: 02-20-02 19:35

I made a routine to print address labels I thought I would share. Its
for a very common 2 5/8" wide x 1" tall address label found in the
States. To use you need to set the page size to 8.5" x 11" and have
the user UNCHECK "Fit to Page" when printing.

function odbc_fetch_array($res) {
$row = array();
$result = array();
if ($result = odbc_fetch_row($res)) {
$nf = odbc_num_fields($res)+1;
for($count=1; $count < $nf; $count++) {
$field_name = odbc_field_name($res, $count);
$field_value = odbc_result($res, $count);
$row[$field_name] = $field_value;
return $row;
// Prints to an Avery 5160 label sheet which is a label
// 2 5/8" wide by 1" tall, they are 3 accross on a page
// and 10 rows per page. (30 per page). The upper left
// corner is label(0,0) The X co-ord goes horizontally
// accross the page and Y goes vertically down the page
// Left/Right page margins are 4.2 MM (1/6 inch)
// Top/Botton page margines are 12.7 MM (.5 inch)
// Horizontal gap between labels is 4.2 MM (1/6 inch)
// There is no vertial gap between labels
// Labels are 66.6 MM (2 5/8") Wide
// Labels are 25.4 MM (1" ) Tall
function Avery5160($x, // X co-ord of label (0-2)
$y, // Y co-ord of label (0-9)
$Data) // String w/ line breaks to print
$LeftMargin = 4.2;
$TopMargin = 12.7;
$LabelWidth = 66.6;
$LabelHeight = 25.45;
// Create Co-Ords of Upper left of the Label
$AbsX = $LeftMargin + (($LabelWidth + 4.22) * $x);
$AbsY = $TopMargin + ($LabelHeight * $y);

// Fudge the Start 3mm inside the label to avoid alignment errors


function PrintAddressLabels($SelectStmt)
global $cnx; // database conneciton in odbcinc.php

$pdf=new FPDF();

$cur = odbc_Exec($cnx,$SelectStmt);

if (!$cur) {
echo "Database Error";

$x = 0;
$y = 0;
while (TRUE) {
if ($row = odbc_fetch_array($cur) ) {
$LabelText = sprintf("%s\n%s\n%s, %s, %s",

$y++; // next row
if ($y == 10 ) { // end of page wrap to next column
$y = 0;
if ($x == 3 ) { // end of page
$x = 0;
$y = 0;
} else {
// Error quit printing


Jul 16 '05 #1
0 19824

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Eric Linders | last post by:
Hi, I have customer contact information in a MySQL DB. The standard stuff: first name, last name, city, state, zip, etc. I'd like to write a PHP script that will take a customer ID range...
by: Chris B | last post by:
Does anyone know of a way in VB.net, to implement the following functionality in printing address labels. Allowing the user to select from which location on a stadard address label sheet (Avery...
by: Frank | last post by:
Hello, I hope this is the correct group to ask this question. I am fairly new to programming, but have a gut feeling this is a pretty easy problem to overcome. I hope I can explain the problem...
by: K. | last post by:
Hello! Could you be so kind and help me with one problem I have. I would like to put an image into the table while creating PDF file. I use fpdf class (www.fpdf.org). I cannot find any...
by: FredBear | last post by:
I am just coming to grips with php, Dreamweaver and MySQL and I want to make a facility available for the members of the group I am creating my web site for. I want them to be able to print-out a...
by: Steve | last post by:
been gleening the user docs for fpdf. there's one simple example for using the image function. i can't seem to get it to work. has anyone else had problems with this, and if so, what did you do to...
by: cappieins | last post by:
Hi, i've got a problem using PHP FPDF library to create PDF files send inline to a browser window. The created PDF file opens correctly in the browser (IE 6), but if I want to save it to my...
by: Sergei Riaguzov | last post by:
Hi, I'm having problems with fpdf v.1.1 used on the site - it doesn't open all PDFs with setSourceFile it says something about "missing xref headers". So I tried to install a newer fpdf version...
by: Steven Nagy | last post by:
Hiyas Our app has a search field where you can select a country drop down and then enter some search criteria that is address based. We want the labels on the search form to change based on what...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.