PHP to PDF mailing labels

Joined: 01/23/2010

I'm using the script at the link below:
http://www.ros.co.nz/pdf/user.php

I can get the pdf file to generate, but I'm having trouble figuring out how to get the mysql data to populate into the labels, the arrays, etc..

Here is the code I have so far:

<?php
## include the class
include ('class.label.inc');
## connect to the database
$host = 'localhost';
$user = 'myusername';
$password = 'mypassword';

$database = 'mydatabase';
$query = 'select * from employees';
//--------------------------------------------------

// open the connection to the db server
$link = mysql_connect($host,$user,$password);
// change to the right database
mysql_select_db($database);
// do the SQL query
$query = "SELECT employee_name, street_address, City, state, zip_code FROM employees ORDER BY employee_name";
$result = mysql_query($query) or die('Error, query failed');
while(
$data[] =  mysql_fetch_assoc($result)) {}

## choose a labeltype
$labeltype="Av5160";

## create a new instance of the class of that labeltype
$label= new Clabel($labeltype);

// initialize the array
$data = array();
$info=array(1=>array('line1'=>'employee_name', 'line2'=>'street_address', 'line3'=>'', 'line4'=>'City'.'state'.'zip_code'),);
//reset($info); ## just to be sure

## make the labels!
$label->makeLabel($info);
?>

I'd really appreciate some help.

Thanks.

Joined: 11/28/2008
When you are running it

When you are running it through while($data[] = mysql_r... then you init the variable again with $data = array() its resetting the data that you pull from the database. Or somethin else is goin on there. Why not do it the traditional way?

while($row = mysql_fetch_assoc($result))
{
$labeltype = "Av5160";
$info = array( 1 => array( 'line1' => $info['employee_name'], 'line2' => 'street_address' ));
$label = new Clabel($labeltype);
$label->makeLabel($info);
}

WARNING: No exposure to the Son will cause burning!

Portfolio Site | Production Blog |

Joined: 01/23/2010
Thank you. That helps a lot.

Thank you. That helps a lot. Just learning a way, much less a traditional way is a little bit of a challenge when you're self taught. I do appreciate the help.