I open a dB to retrieve data from 257 records. I wrote code to print business cards on A4 business card stock. The code either prints each card on its own sheet (257 sheets) or I get the first 10 records printed identically on 26 sheets. Help. I need each record printed on its own business card. I think I’m overthinking the problem and making it more difficult than it is. I am using a ‘while’ loop.
Well, this IS a code site… Show some code and the while loop…
Here is the code that generates 1 page of 10 business cards. I need help generating a card for each record, not just 10. Stuck. Help!
<?php
//Open database connection
$username="";$password="";$database="annual_show";
mysql_connect(mysqlcluster23,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM entries ORDER BY `ENTRY_ID` ASC LIMIT 0, 500 ";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
require('fpdf.php');
class PDF extends FPDF
{
}
$pdf = new PDF();
$pdf->AddPage('P','A4');
$i=0;
while ($i <= 10)
{
// COLUMN 1
//LABEL 1
$f1=mysql_result($result,$i,"ENTRY_ID");
$pdf->setFont("Arial","","30");
$pdf->setXY(15, 13);
$pdf->Cell(10, 10, $f1, 0, 0,'L', 0);
$f2=mysql_result($result,$i,"Class_Number");
$pdf->setFont("Arial","U","14");
$pdf->setXY(37, 10);
$pdf->Cell(10, 10, "CLS", 0, 0, "L", 0);
$pdf->setFont("Arial","","14");
$pdf->setXY(48, 10);
$pdf->Cell(10, 10, $f2, 0, 0,'L', 0);
$f3=mysql_result($result,$i,"Exhibitor_Number");
$pdf->setFont("Arial","U","14");
$pdf->setXY(62, 10);
$pdf->Cell(10, 10, "XTR", 0, 0, "L", 0);
$pdf->setFont("Arial","","14");
$pdf->setXY(74, 10);
$pdf->Cell(10, 10, $f3, 0, 0,'L', 0);
$f4=mysql_result($result,$i,"Exhibit_Number");
$pdf->setFont("Arial","U","14");
$pdf->setXY(84, 10);
$pdf->Cell(10, 10, "XBT", 0, 0, "L", 0);
$pdf->setFont("Arial","","14");
$pdf->setXY(96, 10);
$pdf->Cell(10, 10, $f4, 0, 0,'L', 0);
$pdf->setFont("Arial","U","10");
$pdf->setXY(37, 18);
$pdf->Cell(10, 10, "Entry", 0, 0, "L", 0);
$f5=mysql_result($result,$i,"Plant_Name_L1");
$pdf->setFont("Arial","","12");
$pdf->setXY(15, 23);
$pdf->Cell(90, 10, $f5, 0, 0,'C', 0);
$f6=mysql_result($result,$i,"Plant_Name_L2");
$pdf->setXY(15, 28);
$pdf->Cell(90, 10, $f6, 0, 0,'C', 0);
$f7=mysql_result($result,$i,"Plant_Name_L3");
$pdf->setXY(15, 33);
$pdf->Cell(90, 10, $f7, 0, 0,'C', 0);
$pdf->setFont("Arial","U","10");
$pdf->setXY(37, 38);
$pdf->Cell(10, 10, "Cross", 0, 0, "L", 0);
$f8=mysql_result($result,$i,"Cross_Name_L1");
$pdf->setFont("Arial","","12");
$pdf->setXY(15, 43);
$pdf->Cell(90, 10, $f8, 0, 0,'C', 0);
$f9=mysql_result($result,$i,"Cross_Name_L2");
$pdf->setXY(15, 48);
$pdf->Cell(90, 10, $f9, 0, 0,'C', 0);
$f10=mysql_result($result,$i,"Cross_Name_L3");
$pdf->setXY(15, 53);
$pdf->Cell(90, 10, $f10, 0, 0,'C', 0);
//LABEL 2
$i = ($i + 1);
$f1=mysql_result($result,$i,"ENTRY_ID");
$pdf->setFont("Arial","","30");
$pdf->setXY(15, 64);
$pdf->Cell(10, 10, $f1, 0, 0,'L', 0);
$f2=mysql_result($result,$i,"Class_Number");
$pdf->setFont("Arial","U","14");
$pdf->setXY(37, 61);
$pdf->Cell(10, 10, "CLS", 0, 0, "L", 0);
$pdf->setFont("Arial","","14");
$pdf->setXY(48, 61);
$pdf->Cell(10, 10, $f2, 0, 0,'L', 0);
$f3=mysql_result($result,$i,"Exhibitor_Number");
$pdf->setFont("Arial","U","14");
$pdf->setXY(62, 61);
$pdf->Cell(10, 10, "XTR", 0, 0, "L", 0);
$pdf->setFont("Arial","","14");
$pdf->setXY(74, 61);
$pdf->Cell(10, 10, $f3, 0, 0,'L', 0);
$f4=mysql_result($result,$i,"Exhibit_Number");
$pdf->setFont("Arial","U","14");
$pdf->setXY(84, 61);
$pdf->Cell(10, 10, "XBT", 0, 0, "L", 0);
$pdf->setFont("Arial","","14");
$pdf->setXY(96, 61);
$pdf->Cell(10, 10, $f4, 0, 0,'L', 0);
$pdf->setFont("Arial","U","10");
$pdf->setXY(37, 69);
$pdf->Cell(10, 10, "Entry", 0, 0, "L", 0);
$f5=mysql_result($result,$i,"Plant_Name_L1");
$pdf->setFont("Arial","","12");
$pdf->setXY(15, 74);
$pdf->Cell(90, 10, $f5, 0, 0,'C', 0);
$f6=mysql_result($result,$i,"Plant_Name_L2");
$pdf->setXY(15, 79);
$pdf->Cell(90, 10, $f6, 0, 0,'C', 0);
$f7=mysql_result($result,$i,"Plant_Name_L3");
$pdf->setXY(15, 84);
$pdf->Cell(90, 10, $f7, 0, 0,'C', 0);
$pdf->setFont("Arial","U","10");
$pdf->setXY(37, 89);
$pdf->Cell(10, 10, "Cross", 0, 0, "L", 0);
$f8=mysql_result($result,$i,"Cross_Name_L1");
$pdf->setFont("Arial","","12");
$pdf->setXY(15, 94);
$pdf->Cell(90, 10, $f8, 0, 0,'C', 0);
$f9=mysql_result($result,$i,"Cross_Name_L2");
$pdf->setXY(15, 99);
$pdf->Cell(90, 10, $f9, 0, 0,'C', 0);
$f10=mysql_result($result,$i,"Cross_Name_L3");
$pdf->setXY(15, 104);
$pdf->Cell(90, 10, $f10, 0, 0,'C', 0);
//LABEL 3
$i = ($i + 2);
$f1=mysql_result($result,$i,"ENTRY_ID");
$pdf->setFont("Arial","","30");
$pdf->setXY(15, 114);
$pdf->Cell(10, 10, $f1, 0, 0,'L', 0);
$f2=mysql_result($result,$i,"Class_Number");
$pdf->setFont("Arial","U","14");
$pdf->setXY(37, 111);
$pdf->Cell(10, 10, "CLS", 0, 0, "L", 0);
$pdf->setFont("Arial","","14");
$pdf->setXY(48, 111);
$pdf->Cell(10, 10, $f2, 0, 0,'L', 0);
$f3=mysql_result($result,$i,"Exhibitor_Number");
$pdf->setFont("Arial","U","14");
$pdf->setXY(62, 111);
$pdf->Cell(10, 10, "XTR", 0, 0, "L", 0);
$pdf->setFont("Arial","","14");
$pdf->setXY(74, 111);
$pdf->Cell(10, 10, $f3, 0, 0,'L', 0);
$f4=mysql_result($result,$i,"Exhibit_Number");
$pdf->setFont("Arial","U","14");
$pdf->setXY(84, 111);
$pdf->Cell(10, 10, "XBT", 0, 0, "L", 0);
$pdf->setFont("Arial","","14");
$pdf->setXY(96, 111);
$pdf->Cell(10, 10, $f4, 0, 0,'L', 0);
$pdf->setFont("Arial","U","10");
$pdf->setXY(37, 119);
$pdf->Cell(10, 10, "Entry", 0, 0, "L", 0);
$f5=mysql_result($result,$i,"Plant_Name_L1");
$pdf->setFont("Arial","","12");
$pdf->setXY(15, 124);
$pdf->Cell(90, 10, $f5, 0, 0,'C', 0);
$f6=mysql_result($result,$i,"Plant_Name_L2");
$pdf->setXY(15, 129);
$pdf->Cell(90, 10, $f6, 0, 0,'C', 0);
$f7=mysql_result($result,$i,"Plant_Name_L3");
$pdf->setXY(15, 134);
$pdf->Cell(90, 10, $f7, 0, 0,'C', 0);
$pdf->setFont("Arial","U","10");
$pdf->setXY(37, 139);
$pdf->Cell(10, 10, "Cross", 0, 0, "L", 0);
$f8=mysql_result($result,$i,"Cross_Name_L1");
$pdf->setFont("Arial","","12");
$pdf->setXY(15, 144);
$pdf->Cell(90, 10, $f8, 0, 0,'C', 0);
$f9=mysql_result($result,$i,"Cross_Name_L2");
$pdf->setXY(15, 149);
$pdf->Cell(90, 10, $f9, 0, 0,'C', 0);
$f10=mysql_result($result,$i,"Cross_Name_L3");
$pdf->setXY(15, 154);
$pdf->Cell(90, 10, $f10, 0, 0,'C', 0);
//LABEL 4
$i = ($i + 3);
$f1=mysql_result($result,$i,"ENTRY_ID");
$pdf->setFont("Arial","","30");
$pdf->setXY(15, 165);
$pdf->Cell(10, 10, $f1, 0, 0,'L', 0);
$f2=mysql_result($result,$i,"Class_Number");
$pdf->setFont("Arial","U","14");
$pdf->setXY(37, 162);
$pdf->Cell(10, 10, "CLS", 0, 0, "L", 0);
$pdf->setFont("Arial","","14");
$pdf->setXY(48, 162);
$pdf->Cell(10, 10, $f2, 0, 0,'L', 0);
$f3=mysql_result($result,$i,"Exhibitor_Number");
$pdf->setFont("Arial","U","14");
$pdf->setXY(62, 162);
$pdf->Cell(10, 10, "XTR", 0, 0, "L", 0);
$pdf->setFont("Arial","","14");
$pdf->setXY(74, 162);
$pdf->Cell(10, 10, $f3, 0, 0,'L', 0);
$f4=mysql_result($result,$i,"Exhibit_Number");
$pdf->setFont("Arial","U","14");
$pdf->setXY(84, 162);
$pdf->Cell(10, 10, "XBT", 0, 0, "L", 0);
$pdf->setFont("Arial","","14");
$pdf->setXY(96, 162);
$pdf->Cell(10, 10, $f4, 0, 0,'L', 0);
$pdf->setFont("Arial","U","10");
$pdf->setXY(37, 170);
$pdf->Cell(10, 10, "Entry", 0, 0, "L", 0);
$f5=mysql_result($result,$i,"Plant_Name_L1");
$pdf->setFont("Arial","","12");
$pdf->setXY(15, 175);
$pdf->Cell(90, 10, $f5, 0, 0,'C', 0);
$f6=mysql_result($result,$i,"Plant_Name_L2");
$pdf->setXY(15, 180);
$pdf->Cell(90, 10, $f6, 0, 0,'C', 0);
$f7=mysql_result($result,$i,"Plant_Name_L3");
$pdf->setXY(15, 185);
$pdf->Cell(90, 10, $f7, 0, 0,'C', 0);
$pdf->setFont("Arial","U","10");
$pdf->setXY(37, 190);
$pdf->Cell(10, 10, "Cross", 0, 0, "L", 0);
$f8=mysql_result($result,$i,"Cross_Name_L1");
$pdf->setFont("Arial","","12");
$pdf->setXY(15, 195);
$pdf->Cell(90, 10, $f8, 0, 0,'C', 0);
$f9=mysql_result($result,$i,"Cross_Name_L2");
$pdf->setXY(15, 200);
$pdf->Cell(90, 10, $f9, 0, 0,'C', 0);
$f10=mysql_result($result,$i,"Cross_Name_L3");
$pdf->setXY(15, 205);
$pdf->Cell(90, 10, $f10, 0, 0,'C', 0);
//LABEL 5
$i = ($i + 4);
$f1=mysql_result($result,$i,"ENTRY_ID");
$pdf->setFont("Arial","","30");
$pdf->setXY(15, 216);
$pdf->Cell(10, 10, $f1, 0, 0,'L', 0);
$f2=mysql_result($result,$i,"Class_Number");
$pdf->setFont("Arial","U","14");
$pdf->setXY(37, 213);
$pdf->Cell(10, 10, "CLS", 0, 0, "L", 0);
$pdf->setFont("Arial","","14");
$pdf->setXY(48, 213);
$pdf->Cell(10, 10, $f2, 0, 0,'L', 0);
$f3=mysql_result($result,$i,"Exhibitor_Number");
$pdf->setFont("Arial","U","14");
$pdf->setXY(62, 213);
$pdf->Cell(10, 10, "XTR", 0, 0, "L", 0);
$pdf->setFont("Arial","","14");
$pdf->setXY(74, 213);
$pdf->Cell(10, 10, $f3, 0, 0,'L', 0);
$f4=mysql_result($result,$i,"Exhibit_Number");
$pdf->setFont("Arial","U","14");
$pdf->setXY(84, 213);
$pdf->Cell(10, 10, "XBT", 0, 0, "L", 0);
$pdf->setFont("Arial","","14");
$pdf->setXY(96, 213);
$pdf->Cell(10, 10, $f4, 0, 0,'L', 0);
$pdf->setFont("Arial","U","10");
$pdf->setXY(37, 221);
$pdf->Cell(10, 10, "Entry", 0, 0, "L", 0);
$f5=mysql_result($result,$i,"Plant_Name_L1");
$pdf->setFont("Arial","","12");
$pdf->setXY(15, 226);
$pdf->Cell(90, 10, $f5, 0, 0,'C', 0);
$f6=mysql_result($result,$i,"Plant_Name_L2");
$pdf->setXY(15, 231);
$pdf->Cell(90, 10, $f6, 0, 0,'C', 0);
$f7=mysql_result($result,$i,"Plant_Name_L3");
$pdf->setXY(15, 236);
$pdf->Cell(90, 10, $f7, 0, 0,'C', 0);
$pdf->setFont("Arial","U","10");
$pdf->setXY(37, 241);
$pdf->Cell(10, 10, "Cross", 0, 0, "L", 0);
$f8=mysql_result($result,$i,"Cross_Name_L1");
$pdf->setFont("Arial","","12");
$pdf->setXY(15, 246);
$pdf->Cell(90, 10, $f8, 0, 0,'C', 0);
$f9=mysql_result($result,$i,"Cross_Name_L2");
$pdf->setXY(15, 251);
$pdf->Cell(90, 10, $f9, 0, 0,'C', 0);
$f10=mysql_result($result,$i,"Cross_Name_L3");
$pdf->setXY(15, 256);
$pdf->Cell(90, 10, $f10, 0, 0,'C', 0);
//COLUMN 2
//LABEL 6
$i = ($i + 5);
$f1=mysql_result($result,$i,"ENTRY_ID");
$pdf->setFont("Arial","","30");
$pdf->setXY(103, 13);
$pdf->Cell(10, 10, $f1, 0, 0,'L', 0);
$f2=mysql_result($result,$i,"Class_Number");
$pdf->setFont("Arial","U","14");
$pdf->setXY(125, 10);
$pdf->Cell(10, 10, "CLS", 0, 0, "L", 0);
$pdf->setFont("Arial","","14");
$pdf->setXY(136, 10);
$pdf->Cell(10, 10, $f2, 0, 0,'L', 0);
$f3=mysql_result($result,$i,"Exhibitor_Number");
$pdf->setFont("Arial","U","14");
$pdf->setXY(150, 10);
$pdf->Cell(10, 10, "XTR", 0, 0, "L", 0);
$pdf->setFont("Arial","","14");
$pdf->setXY(162, 10);
$pdf->Cell(10, 10, $f3, 0, 0,'L', 0);
$f4=mysql_result($result,$i,"Exhibit_Number");
$pdf->setFont("Arial","U","14");
$pdf->setXY(172, 10);
$pdf->Cell(10, 10, "XBT", 0, 0, "L", 0);
$pdf->setFont("Arial","","14");
$pdf->setXY(184, 10);
$pdf->Cell(10, 10, $f4, 0, 0,'L', 0);
$pdf->setFont("Arial","U","10");
$pdf->setXY(125, 18);
$pdf->Cell(10, 10, "Entry", 0, 0, "L", 0);
$f5=mysql_result($result,$i,"Plant_Name_L1");
$pdf->setFont("Arial","","12");
$pdf->setXY(103, 23);
$pdf->Cell(90, 10, $f5, 0, 0,'C', 0);
$f6=mysql_result($result,$i,"Plant_Name_L2");
$pdf->setXY(103, 28);
$pdf->Cell(90, 10, $f6, 0, 0,'C', 0);
$f7=mysql_result($result,$i,"Plant_Name_L3");
$pdf->setXY(103, 33);
$pdf->Cell(90, 10, $f7, 0, 0,'C', 0);
$pdf->setFont("Arial","U","10");
$pdf->setXY(125, 38);
$pdf->Cell(10, 10, "Cross", 0, 0, "L", 0);
$f8=mysql_result($result,$i,"Cross_Name_L1");
$pdf->setFont("Arial","","12");
$pdf->setXY(103, 43);
$pdf->Cell(90, 10, $f8, 0, 0,'C', 0);
$f9=mysql_result($result,$i,"Cross_Name_L2");
$pdf->setXY(103, 48);
$pdf->Cell(90, 10, $f9, 0, 0,'C', 0);
$f10=mysql_result($result,$i,"Cross_Name_L3");
$pdf->setXY(103, 53);
$pdf->Cell(90, 10, $f10, 0, 0,'C', 0);
//LABEL 7
$i = ($i + 6);
$f1=mysql_result($result,$i,"ENTRY_ID");
$pdf->setFont("Arial","","30");
$pdf->setXY(103, 64);
$pdf->Cell(10, 10, $f1, 0, 0,'L', 0);
$f2=mysql_result($result,$i,"Class_Number");
$pdf->setFont("Arial","U","14");
$pdf->setXY(125, 61);
$pdf->Cell(10, 10, "CLS", 0, 0, "L", 0);
$pdf->setFont("Arial","","14");
$pdf->setXY(136, 61);
$pdf->Cell(10, 10, $f2, 0, 0,'L', 0);
$f3=mysql_result($result,$i,"Exhibitor_Number");
$pdf->setFont("Arial","U","14");
$pdf->setXY(150, 61);
$pdf->Cell(10, 10, "XTR", 0, 0, "L", 0);
$pdf->setFont("Arial","","14");
$pdf->setXY(162, 61);
$pdf->Cell(10, 10, $f3, 0, 0,'L', 0);
$f4=mysql_result($result,$i,"Exhibit_Number");
$pdf->setFont("Arial","U","14");
$pdf->setXY(172, 61);
$pdf->Cell(10, 10, "XBT", 0, 0, "L", 0);
$pdf->setFont("Arial","","14");
$pdf->setXY(184, 61);
$pdf->Cell(10, 10, $f4, 0, 0,'L', 0);
$pdf->setFont("Arial","U","10");
$pdf->setXY(125, 69);
$pdf->Cell(10, 10, "Entry", 0, 0, "L", 0);
$f5=mysql_result($result,$i,"Plant_Name_L1");
$pdf->setFont("Arial","","12");
$pdf->setXY(103, 74);
$pdf->Cell(90, 10, $f5, 0, 0,'C', 0);
$f6=mysql_result($result,$i,"Plant_Name_L2");
$pdf->setXY(103, 79);
$pdf->Cell(90, 10, $f6, 0, 0,'C', 0);
$f7=mysql_result($result,$i,"Plant_Name_L3");
$pdf->setXY(103, 84);
$pdf->Cell(90, 10, $f7, 0, 0,'C', 0);
$pdf->setFont("Arial","U","10");
$pdf->setXY(125, 89);
$pdf->Cell(10, 10, "Cross", 0, 0, "L", 0);
$f8=mysql_result($result,$i,"Cross_Name_L1");
$pdf->setFont("Arial","","12");
$pdf->setXY(103, 94);
$pdf->Cell(90, 10, $f8, 0, 0,'C', 0);
$f9=mysql_result($result,$i,"Cross_Name_L2");
$pdf->setXY(103, 99);
$pdf->Cell(90, 10, $f9, 0, 0,'C', 0);
$f10=mysql_result($result,$i,"Cross_Name_L3");
$pdf->setXY(103, 104);
$pdf->Cell(90, 10, $f10, 0, 0,'C', 0);
//LABEL 8
$i = ($i + 7);
$f1=mysql_result($result,$i,"ENTRY_ID");
$pdf->setFont("Arial","","30");
$pdf->setXY(103, 114);
$pdf->Cell(10, 10, $f1, 0, 0,'L', 0);
$f2=mysql_result($result,$i,"Class_Number");
$pdf->setFont("Arial","U","14");
$pdf->setXY(125, 111);
$pdf->Cell(10, 10, "CLS", 0, 0, "L", 0);
$pdf->setFont("Arial","","14");
$pdf->setXY(136, 111);
$pdf->Cell(10, 10, $f2, 0, 0,'L', 0);
$f3=mysql_result($result,$i,"Exhibitor_Number");
$pdf->setFont("Arial","U","14");
$pdf->setXY(150, 111);
$pdf->Cell(10, 10, "XTR", 0, 0, "L", 0);
$pdf->setFont("Arial","","14");
$pdf->setXY(162, 111);
$pdf->Cell(10, 10, $f3, 0, 0,'L', 0);
$f4=mysql_result($result,$i,"Exhibit_Number");
$pdf->setFont("Arial","U","14");
$pdf->setXY(172, 111);
$pdf->Cell(10, 10, "XBT", 0, 0, "L", 0);
$pdf->setFont("Arial","","14");
$pdf->setXY(184, 111);
$pdf->Cell(10, 10, $f4, 0, 0,'L', 0);
$pdf->setFont("Arial","U","10");
$pdf->setXY(125, 119);
$pdf->Cell(10, 10, "Entry", 0, 0, "L", 0);
$f5=mysql_result($result,$i,"Plant_Name_L1");
$pdf->setFont("Arial","","12");
$pdf->setXY(103, 124);
$pdf->Cell(90, 10, $f5, 0, 0,'C', 0);
$f6=mysql_result($result,$i,"Plant_Name_L2");
$pdf->setXY(103, 129);
$pdf->Cell(90, 10, $f6, 0, 0,'C', 0);
$f7=mysql_result($result,$i,"Plant_Name_L3");
$pdf->setXY(103, 134);
$pdf->Cell(90, 10, $f7, 0, 0,'C', 0);
$pdf->setFont("Arial","U","10");
$pdf->setXY(125, 139);
$pdf->Cell(10, 10, "Cross", 0, 0, "L", 0);
$f8=mysql_result($result,$i,"Cross_Name_L1");
$pdf->setFont("Arial","","12");
$pdf->setXY(103, 144);
$pdf->Cell(90, 10, $f8, 0, 0,'C', 0);
$f9=mysql_result($result,$i,"Cross_Name_L2");
$pdf->setXY(103, 149);
$pdf->Cell(90, 10, $f9, 0, 0,'C', 0);
$f10=mysql_result($result,$i,"Cross_Name_L3");
$pdf->setXY(103, 154);
$pdf->Cell(90, 10, $f10, 0, 0,'C', 0);
//LABEL 9
$i = ($i + 8);
$f1=mysql_result($result,$i,"ENTRY_ID");
$pdf->setFont("Arial","","30");
$pdf->setXY(103, 165);
$pdf->Cell(10, 10, $f1, 0, 0,'L', 0);
$f2=mysql_result($result,$i,"Class_Number");
$pdf->setFont("Arial","U","14");
$pdf->setXY(125, 162);
$pdf->Cell(10, 10, "CLS", 0, 0, "L", 0);
$pdf->setFont("Arial","","14");
$pdf->setXY(136, 162);
$pdf->Cell(10, 10, $f2, 0, 0,'L', 0);
$f3=mysql_result($result,$i,"Exhibitor_Number");
$pdf->setFont("Arial","U","14");
$pdf->setXY(150, 162);
$pdf->Cell(10, 10, "XTR", 0, 0, "L", 0);
$pdf->setFont("Arial","","14");
$pdf->setXY(162, 162);
$pdf->Cell(10, 10, $f3, 0, 0,'L', 0);
$f4=mysql_result($result,$i,"Exhibit_Number");
$pdf->setFont("Arial","U","14");
$pdf->setXY(172, 162);
$pdf->Cell(10, 10, "XBT", 0, 0, "L", 0);
$pdf->setFont("Arial","","14");
$pdf->setXY(184, 162);
$pdf->Cell(10, 10, $f4, 0, 0,'L', 0);
$pdf->setFont("Arial","U","10");
$pdf->setXY(125, 170);
$pdf->Cell(10, 10, "Entry", 0, 0, "L", 0);
$f5=mysql_result($result,$i,"Plant_Name_L1");
$pdf->setFont("Arial","","12");
$pdf->setXY(103, 175);
$pdf->Cell(90, 10, $f5, 0, 0,'C', 0);
$f6=mysql_result($result,$i,"Plant_Name_L2");
$pdf->setXY(103, 180);
$pdf->Cell(90, 10, $f6, 0, 0,'C', 0);
$f7=mysql_result($result,$i,"Plant_Name_L3");
$pdf->setXY(103, 185);
$pdf->Cell(90, 10, $f7, 0, 0,'C', 0);
$pdf->setFont("Arial","U","10");
$pdf->setXY(125, 190);
$pdf->Cell(10, 10, "Cross", 0, 0, "L", 0);
$f8=mysql_result($result,$i,"Cross_Name_L1");
$pdf->setFont("Arial","","12");
$pdf->setXY(103, 195);
$pdf->Cell(90, 10, $f8, 0, 0,'C', 0);
$f9=mysql_result($result,$i,"Cross_Name_L2");
$pdf->setXY(103, 200);
$pdf->Cell(90, 10, $f9, 0, 0,'C', 0);
$f10=mysql_result($result,$i,"Cross_Name_L3");
$pdf->setXY(103, 205);
$pdf->Cell(90, 10, $f10, 0, 0,'C', 0);
//LABEL 10
$i = ($i + 9);
$f1=mysql_result($result,$i,"ENTRY_ID");
$pdf->setFont("Arial","","30");
$pdf->setXY(103, 216);
$pdf->Cell(10, 10, $f1, 0, 0,'L', 0);
$f2=mysql_result($result,$i,"Class_Number");
$pdf->setFont("Arial","U","14");
$pdf->setXY(125, 213);
$pdf->Cell(10, 10, "CLS", 0, 0, "L", 0);
$pdf->setFont("Arial","","14");
$pdf->setXY(136, 213);
$pdf->Cell(10, 10, $f2, 0, 0,'L', 0);
$f3=mysql_result($result,$i,"Exhibitor_Number");
$pdf->setFont("Arial","U","14");
$pdf->setXY(150, 213);
$pdf->Cell(10, 10, "XTR", 0, 0, "L", 0);
$pdf->setFont("Arial","","14");
$pdf->setXY(162, 213);
$pdf->Cell(10, 10, $f3, 0, 0,'L', 0);
$f4=mysql_result($result,$i,"Exhibit_Number");
$pdf->setFont("Arial","U","14");
$pdf->setXY(172, 213);
$pdf->Cell(10, 10, "XBT", 0, 0, "L", 0);
$pdf->setFont("Arial","","14");
$pdf->setXY(184, 213);
$pdf->Cell(10, 10, $f4, 0, 0,'L', 0);
$pdf->setFont("Arial","U","10");
$pdf->setXY(125, 221);
$pdf->Cell(10, 10, "Entry", 0, 0, "L", 0);
$f5=mysql_result($result,$i,"Plant_Name_L1");
$pdf->setFont("Arial","","12");
$pdf->setXY(103, 226);
$pdf->Cell(90, 10, $f5, 0, 0,'C', 0);
$f6=mysql_result($result,$i,"Plant_Name_L2");
$pdf->setXY(103, 231);
$pdf->Cell(90, 10, $f6, 0, 0,'C', 0);
$f7=mysql_result($result,$i,"Plant_Name_L3");
$pdf->setXY(103, 236);
$pdf->Cell(90, 10, $f7, 0, 0,'C', 0);
$pdf->setFont("Arial","U","10");
$pdf->setXY(125, 241);
$pdf->Cell(10, 10, "Cross", 0, 0, "L", 0);
$f8=mysql_result($result,$i,"Cross_Name_L1");
$pdf->setFont("Arial","","12");
$pdf->setXY(103, 246);
$pdf->Cell(90, 10, $f8, 0, 0,'C', 0);
$f9=mysql_result($result,$i,"Cross_Name_L2");
$pdf->setXY(103, 251);
$pdf->Cell(90, 10, $f9, 0, 0,'C', 0);
$f10=mysql_result($result,$i,"Cross_Name_L3");
$pdf->setXY(103, 256);
$pdf->Cell(90, 10, $f10, 0, 0,'C', 0);
$i++;
$pdf->AddPage();
}
$pdf->Output();
?>
Okay, the code you show is hard coding each label. You just need to hard-code the label once and use
code to alter the positioning and the cols, etc. We can help you do this, but…
First, no programmer here will write MySQL code. It is no longer used and is not even in the newest versions of PHP. You need to move up to MySQLi (improved version) OR even better PDO. And, you should use prepared-statements to protect your site from hackers.
Next, do you need this to be a PDF? You could simply use
This would be easier, I think. But, you can do it with a PDF and the FPDF library. You would just need to
alter the positioning commands to be programmed, not hard-coded. Also, you would need to add a new page after it fills out the current page. So, you are creating a set of 10 cards per page. And, using SETXY to position various parts of the card inside the correct area of the page. You would need to change these settings using a base number. Looking at your listing, I could not understand the layout your are using.
You would need to set a base for X and Y and then adjust these for each row and col of the cards.
So, card number 1 would be started at the smallest X/Y. Then, as you move to card 2, you would just adjust
the col Y value. Then, when you move down a row, you would add a number for each row. And, for each
part of one card, you would adjust the base values. I would guess something like below would work for you.
But, I can’t test it for a couple days for you. But, you might get the idea from it…
require('fpdf.php');
class PDF extends FPDF { }
$pdf = new PDF();
// Set first label's position
$label = 1;
// Move thru all cards
while ($row=mysql_fetch_assoc($result)) {
// $row contains data for each card to be set up
// First check if this is the first of 10 cards, if so, add new page
if ($label==1) { $pdf->AddPage('P','A4'); }
// If label number is odd it's on left, even on right, adjust as needed
// Also set up row number for card using simple math
$current_y = 10;
if ($label % 2 == 0) { $current_y = 61; }
// Also set up row number for card using simple math
$current_x = 15+(103*($label/2)); // 2 per row means 5 down, so 10/2 would give 1 to 5
// Process card
$pdf->setFont("Arial","","30");
$pdf->setXY($current_x, $current_y+3);
$pdf->Cell(10, 10, $row["ENTRY_ID"], 0, 0,'L', 0);
$pdf->setFont("Arial","U","14");
$pdf->setXY($current_x+22, $current_y);
$pdf->Cell(10, 10, "CLS", 0, 0, "L", 0);
$pdf->setFont("Arial","","14");
$pdf->setXY($current_x+33, $current_y);
$pdf->Cell(10, 10, $row["Class_Number"], 0, 0,'L', 0);
$pdf->setFont("Arial","U","14");
$pdf->setXY($current_x+47, $current_y);
$pdf->Cell(10, 10, "XTR", 0, 0, "L", 0);
$pdf->setFont("Arial","","14");
$pdf->setXY($current_x+59, $current_y);
$pdf->Cell(10, 10, $row["Exhibitor_Number"], 0, 0,'L', 0);
$pdf->setFont("Arial","U","14");
$pdf->setXY($current_x+69, $current_y);
$pdf->Cell(10, 10, "XBT", 0, 0, "L", 0);
$pdf->setFont("Arial","","14");
$pdf->setXY($current_x+81, $current_y);
$pdf->Cell(10, 10, $row["Exhibit_Number"], 0, 0,'L', 0);
$pdf->setFont("Arial","U","10");
$pdf->setXY($current_x+22, $current_y+8);
$pdf->Cell(10, 10, "Entry", 0, 0, "L", 0);
$pdf->setFont("Arial","","12");
$pdf->setXY($current_x, $current_y+13);
$pdf->Cell(90, 10, $row["Plant_Name_L1"], 0, 0,'C', 0);
$pdf->setXY($current_x, $current_y+18);
$pdf->Cell(90, 10, $row["Plant_Name_L2"], 0, 0,'C', 0);
$pdf->setXY($current_x, $current_y+23);
$pdf->Cell(90, 10, $row["Plant_Name_L3"], 0, 0,'C', 0);
$pdf->setFont("Arial","U","10");
$pdf->setXY($current_x+22, $current_y+28);
$pdf->Cell(10, 10, "Cross", 0, 0, "L", 0);
$pdf->setFont("Arial","","12");
$pdf->setXY($current_x, $current_y+33);
$pdf->Cell(90, 10, $row["Cross_Name_L1"], 0, 0,'C', 0);
$pdf->setXY($current_x, $current_y+38);
$pdf->Cell(90, 10, $row["Cross_Name_L2"], 0, 0,'C', 0);
$pdf->setXY($current_x, $current_y+43);
$pdf->Cell(90, 10, $row["Cross_Name_L3"], 0, 0,'C', 0);
// Increment the label counter, but, if over 10 reset to 1
$label = $label+1;
if($label==11) { $label = 1; }
}
Ernie:
I worked on your code rework. I can either get a single column of 5 cards per page (52 pages) or 10 cards per page (26 pages) with all 10 cards superimposed on one another. I'm sure it's a looping and/or math incrementing problem. Any help on the matter? You can view the result at www.gcos.org/FPDF/test.php
Code is included:
<?php require('fpdf.php'); class PDF extends FPDF { } $pdf = new PDF(); // Set first label's position $label = 1; // Move through all cards $username="registrar";$password="23Skinner47";$database="annual_show"; mysql_connect(mysqlcluster23,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM entries ORDER BY `ENTRY_ID` ASC LIMIT 0, 500 "; $result=mysql_query($query);$num=mysql_numrows($result);mysql_close(); while($row = mysql_fetch_array($result)) { // $row contains data for each card to be set up // First check if this is the first of 10 cards, if so, add new page if ($label==1) { $pdf->AddPage('P','A4');} // If label number is odd it's on left, even on right, adjust as needed // Also set up row number for card using simple math { $current_y = 15; } // if ($label % 2 == 0) { $current_y = 61; } // Also set up row number for card using simple math $current_x = (13+13*($label/2)); // 2 per row means 5 down, so 10/2 would give 1 to 5 // Process card $pdf->setFont("Arial","","30"); $pdf->setXY($current_x, $current_y+3); $pdf->Cell(10, 10, $row["ENTRY_ID"], 0, 0,'L', 0); $pdf->setFont("Arial","U","14"); $pdf->setXY($current_x+22, $current_y); $pdf->Cell(10, 10, "CLS", 0, 0, "L", 0); $pdf->setFont("Arial","","14"); $pdf->setXY($current_x+33, $current_y); $pdf->Cell(10, 10, $row["Class_Number"], 0, 0,'L', 0); $pdf->setFont("Arial","U","14"); $pdf->setXY($current_x+47, $current_y); $pdf->Cell(10, 10, "XTR", 0, 0, "L", 0); $pdf->setFont("Arial","","14"); $pdf->setXY($current_x+59, $current_y); $pdf->Cell(10, 10, $row["Exhibitor_Number"], 0, 0,'L', 0); $pdf->setFont("Arial","U","14"); $pdf->setXY($current_x+69, $current_y); $pdf->Cell(10, 10, "XBT", 0, 0, "L", 0); $pdf->setFont("Arial","","14"); $pdf->setXY($current_x+81, $current_y); $pdf->Cell(10, 10, $row["Exhibit_Number"], 0, 0,'L', 0); $pdf->setFont("Arial","U","10"); $pdf->setXY($current_x+22, $current_y+8); $pdf->setFont("Arial","","12"); $pdf->setXY($current_x, $current_y+13); $pdf->Cell(90, 10, $row["Plant_Name_L1"], 0, 0,'C', 0); $pdf->setXY($current_x, $current_y+18); $pdf->Cell(90, 10, $row["Plant_Name_L2"], 0, 0,'C', 0); $pdf->setXY($current_x, $current_y+23); $pdf->Cell(90, 10, $row["Plant_Name_L3"], 0, 0,'C', 0); $pdf->setFont("Arial","U","10"); $pdf->setXY($current_x+22, $current_y+28); $pdf->setFont("Arial","","12"); $pdf->setXY($current_x, $current_y+33); $pdf->Cell(90, 10, $row["Cross_Name_L1"], 0, 0,'C', 0); $pdf->setXY($current_x, $current_y+38); $pdf->Cell(90, 10, $row["Cross_Name_L2"], 0, 0,'C', 0); $pdf->setXY($current_x, $current_y+43); $pdf->Cell(90, 10, $row["Cross_Name_L3"], 0, 0,'C', 0); // Increment the label counter, but, if over 10 reset to 1 $label = ($label+1); if($label==11) { $label = 1; } } $pdf->Output();Your code was hard to read, but, I have it in my editor now.
Can you please dummy up a display of how one label should look and I will match the code up as needed for you… Thanks!
Got it working on my end, just do not know the exact layout of the data and the headings.
But, put this part in for the top part of the WHILE loop:
$label = 1; while($row = mysql_fetch_array($result)) { // $row contains data for each card to be set up // First check if this is the first of 10 cards, if so, add new page if ($label==1) { $pdf->AddPage('P','A4'); } // If label number is odd it's on left, even on right, adjust as needed // Set the col first $current_x = 15; if ($label % 2 == 0) { $current_x = 110; } // Set the row up next $current_y = (10+30*intval((($label-1) / 2))); // 2 per row means 5 down, so this calc would give 0 to 4 // Process card $pdf->setFont("Arial","","30"); $pdf->setXY($current_x, $current_y+3);
I used some dummy data, so not 100% sure on the layout, but, give it a try. I will be gone for the next 6-7 hours at a Texas Holdem get together… So, will have to check in at about Midnight EST… Good luck!
The FPDF site has a class to do this - http://www.fpdf.org/en/script/script29.php
All you have to do is pick an existing layout or define your own, then supply the data.
Very nice Phdr! I Googled around for that as I thought someone must have it but did not find it.
Ernie - your help in figuring out the business card printing in FPDF was great! With some tweaking it worked like a charm!
Can you help with another difficulty? Same db. I can format page to only print no more than 3 records per page; I also want a page break upon a change in the “Class_Number” field. Code is included as is a link to the form accessing the db data. Link is http://www.gcos.org/ANNUAL_SHOW/REGISTRATION/PRINT_DATA/print_team_judging_sheets.html
Code follows
<?php // Get user inputs $team = $_POST['TEAM']; // open registration database $username="";$password="";$database="annual_show"; mysql_connect(mysqlcluster23,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); // Select data from judging teams table $query="SELECT * FROM judging_teams WHERE Team_Number='$team' ORDER BY Team_Number ASC LIMIT 0, 500"; $result=mysql_query($query);$num=mysql_numrows($result);mysql_close(); $i=0; while ($i < $num) { $f1=mysql_result($result,$i,"Team_Number"); $f2=mysql_result($result,$i,"Lead_Judge"); $f3=mysql_result($result,$i,"Judge_1"); $f4=mysql_result($result,$i,"Judge_2"); $f5=mysql_result($result,$i,"Judge_3"); $f6=mysql_result($result,$i,"Judge_4"); $f7=mysql_result($result,$i,"Head_Clerk"); $f8=mysql_result($result,$i,"Ribbon_Clerk"); $f9=mysql_result($result,$i,"Spotter"); $f10=mysql_result($result,$i,"Observer_1"); $f11=mysql_result($result,$i,"Observer_2"); $f12=mysql_result($result,$i,"Observer_3"); $f13=mysql_result($result,$i,"Observer_4"); $i++; } require('fpdf.php'); class PDF extends FPDF { //Page header function Header() { } //Page footer function Footer() { //Position at 2.5 cm from bottom $this->SetY(-25); //Arial italic 8 $this->SetFont('Arial','',8); //Page number $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C'); } } $pdf = new PDF(); $pdf->AddPage('L','A4'); // necessary for x of y page numbers to appear in document $pdf->AliasNbPages(); $pdf->SetAutoPageBreak(false); // document properties $pdf->SetFont('Arial','U',14); $pdf->Cell(40,10,'List of Show Entries for Team '."$team"); // Add date report run $pdf->SetFont('Arial','',10); $pdf->Setx(10); $pdf->Sety(5); $date = date("F j, Y"); $pdf->Cell(40,30,'Report date: '.$date); $pdf->SetDrawColor(0, 0, 0); //black //table header $pdf->SetFillColor(170, 170, 170); //gray $pdf->setFont("Arial","","10"); $pdf->setXY(10, 29.5); // CHANGE THESE TO REPRESENT YOUR FIELDS $pdf->Cell(20, 5, "", 1, 0, "L", 1); $pdf->Cell(40, 5, "JUDGES", 1, 0, "C", 1); $pdf->Cell(60, 5, "CLERKS", 1, 0, "C", 1); $pdf->Cell(60, 5, "OBSERVERS", 1, 0, "C", 1); $pdf->setXY(10,34.5); $pdf->Cell(20,5, "LEAD ",1,0, "R", 1); $pdf->setXY(10,39.5); $pdf->Cell(20,5, "JUDGE 1 ",1,0, "R", 1); $pdf->setXY(10,44.5); $pdf->Cell(20,5, "JUDGE 2 ",1,0, "R", 1); $pdf->setXY(10,49.5); $pdf->Cell(20,5, "JUDGE 3 ",1,0, "R", 1); $pdf->setXY(10,54.5); $pdf->Cell(20,5, "JUDGE 4 ",1,0, "R", 1); $pdf->setXY(70,34.5); $pdf->Cell(20,5, "HEAD ",1,0, "R", 1); $pdf->setXY(70,39.5); $pdf->Cell(20,5, "RIBBON ",1,0, "R", 1); $pdf->setXY(70,44.5); $pdf->Cell(20,5, "SPOTTER ",1,0, "R", 1); $pdf->setXY(130,34.5); $pdf->Cell(20,5, "1 ",1,0, "R", 1); $pdf->setXY(130,39.5); $pdf->Cell(20,5, "2 ",1,0, "R", 1); $pdf->setXY(130,44.5); $pdf->Cell(20,5, "3 ",1,0, "R", 1); $pdf->setXY(130,49.5); $pdf->Cell(20,5, "4 ",1,0, "R", 1); $pdf->SetFillColor(198, 245, 175); $pdf->setXY(30,34.5); $pdf->Cell(40,5, "$f2",1,0, "L", 1); $pdf->setXY(30,39.5); $pdf->Cell(40,5, "$f3",1,0, "L", 1); $pdf->setXY(30,44.5); $pdf->Cell(40,5, "$f4",1,0, "L", 1); $pdf->setXY(30,49.5); $pdf->Cell(40,5, "$f5",1,0, "L", 1); $pdf->setXY(30,54.5); $pdf->Cell(40,5, "$f6",1,0, "L", 1); $pdf->SetFillColor(198, 245, 175); $pdf->setXY(90,34.5); $pdf->Cell(40,5, "$f7",1,0, "L", 1); $pdf->setXY(90,39.5); $pdf->Cell(40,5, "$f8",1,0, "L", 1); $pdf->setXY(90,44.5); $pdf->Cell(40,5, "$f9",1,0, "L", 1); $pdf->SetFillColor(198, 245, 175); $pdf->setXY(150,34.5); $pdf->Cell(40,5, "$f10",1,0, "L", 1); $pdf->setXY(150,39.5); $pdf->Cell(40,5, "$f11",1,0, "L", 1); $pdf->setXY(150,44.5); $pdf->Cell(40,5, "$f12",1,0, "L", 1); $pdf->setXY(150,49.5); $pdf->Cell(40,5, "$f13",1,0, "L", 1); $pdf->setXY(10,80); $pdf->SetFont('Arial','',14); $pdf->Cell(40,10,'Judging sheets are printed sorted by Class, then Exhibit Location.'); $pdf->setXY(10,90); $pdf->Cell(40,10,'Each page contains the information for one show entry.'); $pdf->setXY(10,100); $pdf->Cell(40,10,'If an entry is mis-classified, please give the entry to the proper judging team.'); $pdf->setXY(10,110); $pdf->Cell(40,10,'Please take the time to indicate the new class to which the entry is assigned.'); $pdf->setXY(10,120); $pdf->Cell(40,10,'Please take the time to record all award information.'); $pdf->setXY(10,130); $pdf->Cell(40,10,'Upon conclusion of your work, please return your team judging sheets to registration.'); $username="registrar";$password="23Skinner47";$database="annual_show"; mysql_connect(mysqlcluster23,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); // Select data from entries table $query="SELECT * FROM entries WHERE Team_Number='$team' ORDER BY Class_Number, Exhibit_Number, ENTRY_ID ASC LIMIT 0, 500"; $result=mysql_query($query);$num=mysql_numrows($result);mysql_close(); $pdf->SetFont('Arial','',14); $pdf->setXY(10,160); $pdf->Cell(40,10,'Team '."$team"); $pdf->setXY(28,160); $pdf->Cell(10,10, 'has'); $pdf->setXY(38, 160); $pdf->Cell(40,10,"$num".' entries'); $pdf->AddPage('L','A4'); $username="registrar";$password="23Skinner47";$database="annual_show"; mysql_connect(mysqlcluster23,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); // Select data from entries table $query="SELECT * FROM entries WHERE Team_Number='$team' ORDER BY Class_Number, Exhibit_Number, ENTRY_ID ASC LIMIT 0, 500"; $result=mysql_query($query);$num=mysql_numrows($result);mysql_close(); $i=0; $x=10; $y=10; while ($i < $num) { $g1=mysql_result($result,$i,"ENTRY_ID"); $g2=mysql_result($result,$i,"Class_Number"); $g3=mysql_result($result,$i,"Exhibitor_Number"); $g4=mysql_result($result,$i,"Exhibit_Number"); $g5=mysql_result($result,$i,"Plant_Name_L1"); $g6=mysql_result($result,$i,"Plant_Name_L2"); $g7=mysql_result($result,$i,"Plant_Name_L3"); $g8=mysql_result($result,$i,"Cross_Name_L1"); $g9=mysql_result($result,$i,"Cross_Name_L2"); $g10=mysql_result($result,$i,"Cross_Name_L3"); $pdf->SetFillColor(170, 170, 170); //gray $pdf->SetFont('Arial','',12); $pdf->setXY($x, $y+15); $pdf->Cell(20, 5, "XBT LOC", 1, 0, "C", 1); $pdf->setXY($x+20, $y+15); $pdf->Cell(10, 5, "$g4", 0, 0, "C", 0); $pdf->setXY($x+40, $y+15); $pdf->Cell(20, 5, "CLASS", 1, 0, "C", 1); $pdf->setXY($x+60, $y+15); $pdf->Cell(15, 5, "$g2", 0, 0, "C", 0); $pdf->setXY($x+80, $y+15); $pdf->Cell(15, 5, "TAG", 1, 0, "C", 1); $pdf->setXY($x+95, $y+15); $pdf->Cell(15, 5, "$g1", 0, 0, "C", 0); $pdf->setXY($x+235,$y+15); $pdf->Cell(20, 5, "XBTOR", 1, 0, "C", 1); $pdf->setXY($x+255,$y+15); $pdf->Cell(10, 5, "$g3", 0, 0, "C", 0); //table header $pdf->SetFillColor(170, 170, 170); //gray $pdf->setXY($x, $y+21); $pdf->SetFont('Arial','',10); $pdf->Cell(133,5.5, "PLANT", 1, 0, "C", 1); $pdf->Cell(133,5.5, "CROSS", 1, 0, "C", 1); $pdf->setFont("Arial","","8"); $pdf->setXY($x, $y+27); $pdf->Cell(133,5.5, "$g5", 0, 0, "C", 1); $pdf->Cell(133,5.5, "$g8", 0, 0, "C", 1); $pdf->setXY($x, $y+33); $pdf->Cell(133,5.5, "$g6", 0, 0, "C", 1); $pdf->Cell(133,5.5, "$g9", 0, 0, "C", 1); $pdf->setXY($x, $y+39); $pdf->Cell(133,5.5, "$g7", 0, 0, "C", 1); $pdf->Cell(133,5.5, "$g10", 0, 0, "C", 1); $pdf->setXY($x-1, $y+60); $pdf->Cell(1,5.5, "|", 0, 0, "L", 0); $pdf->setXY($x-.5, $y+60); $pdf->Cell(133,5.5, "_______________________________________________________________________________________________________________________________________________________ __________________", 0, 0, "L", 0); $pdf->setXY($x+266, $y+60); $pdf->Cell(1,5.5, "|", 0, 0, "R", 0); $pdf->setXY($x+2, $y+55); $pdf->SetFont('Arial','',10); $pdf->Cell(23,5.5, "Place Awards (Circle)", 1, 0, "L", 1); $pdf->setXY($x+45, $y+55); $pdf->Cell(23,5.5, "FIRST SECOND THIRD", 0, 0, "L", 0); $pdf->setXY($x+100, $y+55); $pdf->Cell(25,5.5, "Best of Class?", 1, 0, "L", 1); $pdf->setXY($x+130, $y+55); $pdf->Cell(25,5.5, "Yes", 0, 0, "L", 0); $pdf->setXY($x+150, $y+48); $pdf->Cell(22,5.5, "AOS Awards", 1, 0, "L", 1); $pdf->setXY($x+150, $y+55); $pdf->Cell(26,5.5, "Special Awards", 1, 0, "L", 1); $i++; $y=$y+55; //if more than 3 entries per page print on next page if ($y>140) { $x=10; $y=10; $pdf->setXY($x,$y); $pdf->AddPage('L','A4'); } //if class changes print on next page } $pdf->Output(); ?>Glad you sorted it out. Always a nice feeling when a puzzle is solved!
So, to do the breaking on a change in the fields you would need to save the current field value first.
You would need to set a value such as $current_class_number = “zzzz”; Something not in your class list!
This would be done just before you run your query.
Then, when creating a label, just check for the field. Something like:
$class_num = mysql_result($result,$i,“Class_Number”);
if ( $current_class_number!=$class_num ) {
$pdf->AddPage(‘L’,‘A4’);
$current_class_number = $class_num;
}
This would move to a new page when the class number changes. It would save the new current class number so it would be ready for the next one. The only issue with this is to not do a new page if both the per-page count and the new class happen at the same time. We have it set up so that it adds a new page when it hits the first of a new page. If that happens you would not want to check for a class change as it would cause a blank page to be inserted. (Double add-pages!) Hope that makes sense to you.
One other note. You are using MySQL which is no longer used and might not work at some point in the future. You should consider moving up at least to MySQLi (improved version which is still valid) or better yet, to PDO which is becoming the preferred database system. But, for another time, I think…