Need some help in formatting FPDF output. Upon a change in the value of the field “Class_Number”, I want records printed on a new page. Additionally, I want no more than 3 records per page printed on each page. So far all I can get is to print each record on its own page! Code is included as well as website link.
CODE:
<?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() { } } $pdf = new PDF(); $pdf->AddPage('L','A4'); // 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="";$password="";$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'); $username="";$password="";$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(); $current_class=0; $i=0; $x=10; $y=10; $count=1; while ($i < $num) { if ($count==1) { $pdf->AddPage('L','A4');} $g1=mysql_result($result,$i,"ENTRY_ID"); $class_number=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, "$class_number", 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++; //if class changes print on next page if ($class_number!=$current_class) { $x=10; $y=10; $pdf->setxy($x,$y); $current_class=$class_number; $count = ($count + 1); } //if more than 3 entries per page print on next page if($count=3) { $x=10; $y=10; $pdf->setxy($x,$y); $count = 1; } } $pdf->Output(); ?>Link to website is
www.gcos/org/ANNUAL_SHOW/REGISTRATION/PRINT_DATA/print_team_judging_sheets.html
Use as team input, 1,2,3, or 4