I am modifying a label generation script to create price tags for a flea-market. I have no problems generating the labels from the item records, but I want to use the value from the "supplier_id" column to retrieve the supplier name from another table. I looked into nested queries (which seem to be recommended against), but found another method (JOIN) which I don't quite understand how to do. What would be the best method to accomplish what I want to do?
<?php
define('FPDF_FONTPATH','font/');
require_once('PDF_Label.php');
/*-------------------------------------------------
To create the object, 2 possibilities:
either pass a custom format via an array
or use a built-in AVERY name
-------------------------------------------------*/
// Example of custom format; we start at the second column
//$pdf = new PDF_Label(array('name'=>'perso1', 'paper-size'=>'A4', 'marginLeft'=>1, 'marginTop'=>1, 'NX'=>2, 'NY'=>7, 'SpaceX'=>0, 'SpaceY'=>0, 'width'=>99.1, 'height'=>38.1, 'metric'=>'mm', 'font-size'=>14), 1, 2);
// Standard format
$pdf = new PDF_Label('5160', 'mm', 1, 2);
$pdf->Open();
$pdf->AddPage();
mysql_connect("localhost", "user", "password") or die(mysql_error());
mysql_select_db("PHP_Point_of_Sale") or die(mysql_error());
$result = mysql_query("SELECT * FROM items");
while($row = mysql_fetch_assoc($result)){
$seller_id = $row[supplier_id];
// This is where I want to use $seller_id to find the supplier name in the 'suppliers' table.
$pdf->Add_PDF_Label(sprintf("%s\n%s\n%s%s", $row[item_name] , $row[description] , "$" , $row[unit_price]));
}
// Print labels
//for($i=1;$i<=40;$i++)
// $pdf->Add_PDF_Label(sprintf("%s\n%s\n%s\n%s, %s, %s", "Laurent $i", 'Immeuble Titi', 'av. fragonard', '06000', 'NICE', 'FRANCE'));
//$pdf->Output();
?>
Thank you,
Chris