PHP / FPDI / Loop Question

Hello,
A year ago I had a freelancer create a system for me which exports results from a MySQL Database to make certification cards for students. It creates a PDF using FPDI. The template he made was ONE CARD PER PDF, so very simple.

Today I find myself trying to make a 3 card template, so 3 student cards per PDF. This changes the PHP Code drastically and I am lost.

Right now, we have a foreach statement and it spits out the coordinates of each variable, as far as where it will be placed on the card.

THIS IS SAMPLE DATA. I HAVE REMOVED STUFF FOR SECURITY SO IF YOU SEE ERRORS IN QUERY, THATS WHY.


mysql_select_db($database_db, $db);
$query_rsCourseInfo = sprintf("SELECT scheduledcourses.coursedate, locations.locationname, scheduledcoursesid, locations.locationcity, locations.locationstate, instructors.instructorname, FROM scheduledcourses LEFT JOIN locations ON scheduledcourses.courselocationid = locations.locationsid LEFT JOIN instructors ON scheduledcourses.courseinstructor = instructors.instructorsid LEFT JOIN instructor_creds ON instructors.instructorsid = instructor_creds.instructor_profile_id WHERE scheduledcourses.scheduledcoursesid = %s", GetSQLValueString($colname_rsCourseInfo, "int"));
$rsCourseInfo = mysql_query($query_rsCourseInfo, $db) or die(mysql_error());
$row_rsCourseInfo = mysql_fetch_assoc($rsCourseInfo);
$totalRows_rsCourseInfo = mysql_num_rows($rsCourseInf


$pdf= new fpdi();
$pagecount = $pdf->setSourceFile("pdfcard/pdfs/3Cards.pdf");
foreach ($myprintinglist as $row_rsCourseStudents){
/* first page starts here */
$tplidx = $pdf->ImportPage(1);
$pdf->addPage();
$pdf->useTemplate($tplidx,0,0,210);
$pdf->SetFont('Arial','',12);
$pdf->SetXY(85, 5);
$pdf->Cell(0,0,'');

$pdf->SetFont('Arial','',9);
$pdf->SetXY(125, 27);
$pdf->Cell(0,0,'$studentname');

$pdf->SetXY(165, 27);
$pdf->Cell(0,0,'SAMPLE DATA);
 

$pdf->SetXY(125, 36);
$pdf->Cell(0,0,'City,State');

$pdf->SetXY(158, 36);
$pdf->Cell(25,0,'1-855-555-5555',0,1,"R");
} 

$pdf->Output("temp.pdf", "I");
$pdf->closeParsers();

How do I get 3 different recrods within the same card? right now the foreach is creating a new PDF per record.

I’d start with something like this:

$pdf= new fpdi();
$pagecount = $pdf->setSourceFile("pdfcard/pdfs/3Cards.pdf");
$tplidx = $pdf->ImportPage(1);
for ($i = 0; $i < sizeof($row_rsCourseStudents); $i+=3) { // increment by 3 records, so first iteration has 0-2, second 3-5, etc.
    /* first page starts here */
    $pdf->addPage();
    $pdf->useTemplate($tplidx,0,0,210);
    $pdf->SetFont('Arial','',12);

    for ($j = 0; $j < 3; $j++) // loop through the 3 records we need to process
    {
        $pdf->SetXY(85, 5 + ($j * 20)); // change 20 to be whatever distance is between each template on the page)
        $pdf->Cell(0,0,'');

        $pdf->SetFont('Arial','',9);
        $pdf->SetXY(125, 27 + ($j * 20)); // change 20 to be whatever distance is between each template on the page)
        $pdf->Cell(0,0,'$studentname'); // $row_rsCourseStudents[($i * 3) + $j]['name'] will get you the record for the student

        $pdf->SetXY(165, 27 + ($j * 20)); // change 20 to be whatever distance is between each template on the page)
        $pdf->Cell(0,0,'SAMPLE DATA');
 
        $pdf->SetXY(125, 36 + ($j * 20)); // change 20 to be whatever distance is between each template on the page)
        $pdf->Cell(0,0,'City,State');

        $pdf->SetXY(158, 36 + ($j * 20)); // change 20 to be whatever distance is between each template on the page)
        $pdf->Cell(25,0,'1-855-277-4339',0,1,"R");
    }
} 

$pdf->Output("temp.pdf", "I");
$pdf->closeParsers(); 

Hi CPRADIO, thank you very much for your help
I did implement your solution.I am getting 3 records per card. For the static data its fine, but for the student names its not showing anything.

HEre is what I did.


$pdf= new fpdi();
$pagecount = $pdf->setSourceFile("pdfcard/pdfs/3Cards.pdf");
$tplidx = $pdf->ImportPage(1);
for ($i = 0; $i < sizeof($row_rsCourseStudents); $i+=3) {
/* first page starts here */
$pdf->addPage();
$pdf->useTemplate($tplidx,0,0,210);
$pdf->SetFont('Arial','',12);

  for ($j = 0; $j < 3; $j++) // loop through the 3 records we need to process
  {
	$pdf->SetXY(85, 5 + ($j * 20));
	$pdf->Cell(0,0,'');

	$pdf->SetFont('Arial','',9);
	$pdf->SetXY(125, 27 + ($j * 20));
	$pdf->Cell(0,0,'SCHOOL NAME');
	
	$pdf->SetXY(165, 27 + ($j * 20));
	$pdf->Cell(0,0,'SAMPLENUMBER');
 

	$pdf->SetXY(125, 36 + ($j * 20));
	$pdf->Cell(0,0,'citY,STATE');

	$pdf->SetXY(158, 36 + ($j * 20));
	$pdf->Cell(25,0,'1-855-555-5555',0,1,"R");


	$pdf->SetFont('Arial','',11);

	$pdf->SetXY(15, 47 + ($j * 20));
	$pdf->Cell(58,0,$row_rsCourseStudents[($i * 3) + $j]['studentname'] . ' '. $row_rsCourseStudents[($i * 3) + $j]['studentlastname'],0,1,"C");

	$pdf->SetFont('Arial','',9);
	$pdf->SetXY(135, 54 + ($j * 20));
	$pdf->Cell(45,0,$locationname. ' ' .$coursenumber,0,1,"R");


	$pdf->SetXY(120, 60 + ($j * 20));
	$pdf->Cell(30,0,$row_rsCourseStudents['instructorname'] . ' '. $row_rsCourseStudents['instructorlastname'],0,1,"L");
//aha instructor id
	$pdf->SetXY(135, 60 + ($j * 20));
	$pdf->Cell(45,0,$row_rsCourseStudents['ahainstructorid'],0,1,"R");

//course date
	$coursedate = date('F Y',strtotime($row_rsCourseStudents['coursedate']));
	$expdate = strtotime ('+2 years' , strtotime( $coursedate ) ) ;
	$expdate = date('F Y', $expdate);
	$pdf->SetXY(30, 64 + ($j * 20));
	$pdf->Cell(20,0,$coursedate,0,1,"C");

// coursedate plus 2 years
	$pdf->SetXY(72, 64 + ($j * 20));
	$pdf->Cell(20,0,$expdate,0,1,"C");
	} 
}
$pdf->Output("temp.pdf", "I");
$pdf->closeParsers();


Okay, let’s clean it up a bit so try and figure out the issue quicker

$pdf= new fpdi();
$pagecount = $pdf->setSourceFile("pdfcard/pdfs/3Cards.pdf");
$tplidx = $pdf->ImportPage(1);
for ($i = 0; $i < sizeof($row_rsCourseStudents); $i+=3) {
/* first page starts here */
$pdf->addPage();
$pdf->useTemplate($tplidx,0,0,210);
$pdf->SetFont('Arial','',12);

  for ($j = 0; $j < 3; $j++) // loop through the 3 records we need to process
  {
    $record = $row_rsCourseStudents[($i * 3) + $j];

    $pdf->SetXY(85, 5 + ($j * 20));
    $pdf->Cell(0,0,'');

    $pdf->SetFont('Arial','',9);
    $pdf->SetXY(125, 27 + ($j * 20));
    $pdf->Cell(0,0,'SCHOOL NAME');
    
    $pdf->SetXY(165, 27 + ($j * 20));
    $pdf->Cell(0,0,'SAMPLENUMBER');
 

    $pdf->SetXY(125, 36 + ($j * 20));
    $pdf->Cell(0,0,'citY,STATE');

    $pdf->SetXY(158, 36 + ($j * 20));
    $pdf->Cell(25,0,'1-855-555-5555',0,1,"R");


    $pdf->SetFont('Arial','',11);

    $pdf->SetXY(15, 47 + ($j * 20));
    $pdf->Cell(58,0,$studentname,0,1,"C");

    $pdf->SetFont('Arial','',9);
    $pdf->SetXY(135, 54 + ($j * 20));
    $pdf->Cell(45,0,$locationname. ' ' .$coursenumber,0,1,"R");


    $pdf->SetXY(120, 60 + ($j * 20));
    $pdf->Cell(30,0,$record['instructorname'] . ' '. $record['instructorlastname'],0,1,"L");
//aha instructor id
    $pdf->SetXY(135, 60 + ($j * 20));
    $pdf->Cell(45,0,$record['ahainstructorid'],0,1,"R");

//course date
    $coursedate = date('F Y',strtotime($record['coursedate']));
    $expdate = strtotime ('+2 years' , strtotime( $coursedate ) ) ;
    $expdate = date('F Y', $expdate);
    $pdf->SetXY(30, 64 + ($j * 20));
    $pdf->Cell(20,0,$coursedate,0,1,"C");

// coursedate plus 2 years
    $pdf->SetXY(72, 64 + ($j * 20));
    $pdf->Cell(20,0,$expdate,0,1,"C");
    } 
}
$pdf->Output("temp.pdf", "I");
$pdf->closeParsers();  

Now if you are still not getting the data for each student, put var_dump($row_rsCourseStudents); before $pdf= new fpdi(); Then copy and paste the output here so I can see what the data looks like (feel free to alter the content of the data).

Ok perfect. here is the data. looks like its the query.


array(14) { ["studentsid"]=> string(4) "1933" ["studentsname"]=> string(4) "Mike" ["studentlastname"]=> string(11) "Shaughnessy" ["scheduledcoursesid"]=> string(6) "100645" ["studentemddress"]=> string(15) "otter21@mac.com" ["scheduledid"]=> string(6) "100645" ["coursetypename"]=> string(12) "CPR with AED" ["coursedate"]=> string(10) "2013-09-07" ["locationname"]=> string(38) "Holiday Inn Express Allen Event Center" ["locationcity"]=> string(5) "Allen" ["locationstate"]=> string(2) "TX" ["instructorname"]=> string(9) "Christian" ["instructorlastname"]=> string(9) "Hernandez" ["ahainstructorid"]=> string(11) "04112392307" } FPDF error: Some data has already been output, can't send PDF file (output started at /home/alwaysc/public_html/admin/cardprinting_print3cards.php:108)

FULL QUERIES ON THE PAGE


mysql_select_db($database_db, $db);
$query_rsCourseInfo = sprintf("SELECT scheduledcourses.coursedate, locations.locationname, scheduledcoursesid, locations.locationcity, locations.locationstate, instructors.instructorname, instructors.instructorlastname,  LEFT JOIN locations ON scheduledcourses.courselocationid = locations.locationsid LEFT JOIN instructors ON scheduledcourses.courseinstructor = instructors.instructorsid LEFT JOIN instructor_creds ON instructors.instructorsid = instructor_creds.instructor_profile_id WHERE scheduledcourses.scheduledcoursesid = %s", GetSQLValueString($colname_rsCourseInfo, "int"));
$rsCourseInfo = mysql_query($query_rsCourseInfo, $db) or die(mysql_error());
$row_rsCourseInfo = mysql_fetch_assoc($rsCourseInfo);
$totalRows_rsCourseInfo = mysql_num_rows($rsCourseInfo);

if ($_POST['locationname'] == $row_rsCourseInfo['locationname']) {
	$locationname = $row_rsCourseInfo['locationname'];}
	else {$locationname = $_POST['locationname'];}

$colname_rsCourseStudents = "-1";

$mystudentlist = $_POST["myid"];

mysql_select_db($database_db, $db);

$myprintinglist = array ();

//foreach ($mystudentlist as $uniqestudent)
//echo "<pre>";
//print_r($_POST);
//echo "</pre>";
foreach ($mystudentlist as $uniqestudent)


{
//echo "###$uniqestudent<br>";
  $elementsid = explode ("_", $uniqestudent);
  $scheduledid = $elementsid[0];
  $studentsid =  $elementsid[1];
  
//  echo "---$scheduledid---$studentsid<br>";
 $query_rsCourseStudents = "SELECT students.studentsid, students.studentsname, students.studentlastname, scheduledcoursesid, students.studentemddress, courseregistrations.scheduledid, coursetypes.coursetypename, scheduledcourses.coursedate, locations.locationname, locations.locationcity, locations.locationstate, instructors.instructorname, instructors.instructorlastname, instructor_creds.ahainstructorid FROM courseregistrations LEFT JOIN students ON courseregistrations.studentid = students.studentsid INNER JOIN scheduledcourses ON courseregistrations.scheduledid = scheduledcourses.scheduledcoursesid LEFT JOIN coursetypes ON scheduledcourses.coursetype = coursetypes.coursetypesid LEFT JOIN locations ON scheduledcourses.courselocationid = locations.locationsid LEFT JOIN instructors ON scheduledcourses.courseinstructor = instructors.instructorsid LEFT JOIN instructor_creds ON instructors.instructorsid = instructor_creds.instructor_profile_id WHERE  courseregistrations.scheduledid = $scheduledid and  students.studentsid = $studentsid";
//  echo  $query_rsCourseStudents;
  $rsCourseStudents = mysql_query($query_rsCourseStudents, $db) or die(mysql_error());
  $row_rsCourseStudents = mysql_fetch_assoc($rsCourseStudents);
  mysql_free_result($rsCourseStudents);

Okay, I had made some assumptions as it has been a LONG time since I worked with the mysql_ functions. Here is the updated SQL portion (adjust accordingly)

mysql_select_db($database_db, $db);
$query_rsCourseInfo = sprintf("SELECT scheduledcourses.coursedate, locations.locationname, scheduledcoursesid, locations.locationcity, locations.locationstate, instructors.instructorname, FROM scheduledcourses LEFT JOIN locations ON scheduledcourses.courselocationid = locations.locationsid LEFT JOIN instructors ON scheduledcourses.courseinstructor = instructors.instructorsid LEFT JOIN instructor_creds ON instructors.instructorsid = instructor_creds.instructor_profile_id WHERE scheduledcourses.scheduledcoursesid = %s", GetSQLValueString($colname_rsCourseInfo, "int"));
$rsCourseInfo = mysql_query($query_rsCourseInfo, $db) or die(mysql_error());

// Leave what is above the way you have it, change the lines below to the following)
$row_rsCourseInfo = array();
while ($row = mysql_fetch_assoc($rsCourseInfo))
  $row_rsCourseInfo[] = $row;
$totalRows_rsCourseInfo = mysql_num_rows($rsCourseInfo);

That should populate $row_rsCourseInfo will ALL the records returned from your query.

Ok, i dont want to press my luck here :wink: you have been very helpful.
I think we modified the wrong query.

Let me explain the scenario.

There is a page which lets you tick off the students which you want to print a card for (Which is what the PDF does.)
Those tick boxes go into an array which is what the query does. RIght now its pulling the first name and no others.

The query we modified above is the one that pulls the course info not the students.

Look at query for student names.


$mystudentlist = $_POST["myid"];
mysql_select_db($database_db, $db);
$myprintinglist = array ();
foreach ($mystudentlist as $uniqestudent)
{
  $elementsid = explode ("_", $uniqestudent);
  $scheduledid = $elementsid[0];
  $studentsid =  $elementsid[1];
  
 $query_rsCourseStudents = "SELECT students.studentsid, students.studentsname, students.studentlastname, scheduledcoursesid, students.studentemddress, courseregistrations.scheduledid, coursetypes.coursetypename, scheduledcourses.coursedate, locations.locationname, locations.locationcity, locations.locationstate, instructors.instructorname, instructors.instructorlastname, instructor_creds.ahainstructorid FROM courseregistrations LEFT JOIN students ON courseregistrations.studentid = students.studentsid INNER JOIN scheduledcourses ON courseregistrations.scheduledid = scheduledcourses.scheduledcoursesid LEFT JOIN coursetypes ON scheduledcourses.coursetype = coursetypes.coursetypesid LEFT JOIN locations ON scheduledcourses.courselocationid = locations.locationsid LEFT JOIN instructors ON scheduledcourses.courseinstructor = instructors.instructorsid LEFT JOIN instructor_creds ON instructors.instructorsid = instructor_creds.instructor_profile_id WHERE  courseregistrations.scheduledid = $scheduledid AND students.studentsid = $studentsid";
  $rsCourseStudents = mysql_query($query_rsCourseStudents, $db) or die(mysql_error());
  $row_rsCourseStudents = array();
  while ($row = mysql_fetch_assoc($rsCourseStudents))
  $row_rsCourseStudents[] = $row;
  $totalRows_rsCourseSudents = mysql_num_rows($rsCourseStudents); 

You’d be correct. Okay, so after you made the following PHP code changes for $row_rsCourseStudents, what do you get when you perform var_dump($row_rsCourseStudents); after the $totalRows_rsCourseSudents = mysql_num_rows($rsCourseStudents); line? Do you get an array of students?

When I do the dump I get ALL teh students in an array, when i display on the card, i get only the first student in that array.

Let me put what i have.


 for ($j = 0; $j < 3; $j++) // loop through the 3 records we need to process
  {
    $record = $row_rsCourseStudents[($i * 3) + $j];


then down by the studnet name on the $pdf ->
I have


$pdf->SetXY(15, 47 + ($j * $spacing));
	$pdf->Cell(58,0,$record['studentsname']. ' '. $record['studentlastname'],0,1,"C");

Hmmm… now that doesn’t quite make sense. If you have all of the students displayed in the var_dump, it should be at least iterating over all of them…

Okay, let’s see what the following produces (comment out your current var_dump):

Place the following above the for ($i line

var_dump(sizeof($row_rsCourseStudents));

Then after $record = $row_rsCourseStudents[($i * 3) + $j]; put the following

var_dump($record);

Here are results


int(1) array(14) { ["studentsid"]=> string(4) "2122" ["studentsname"]=> string(4) "Seth" ["studentlastname"]=> string(7) "Doer" ["scheduledcoursesid"]=> string(6) "100696" ["studentemddress"]=> NULL ["scheduledid"]=> string(6) "100696" ["coursetypename"]=> string(22) "Course Type 1" ["coursedate"]=> string(10) "2013-09-06" ["locationname"]=> string(33) " Training Center" ["locationcity"]=> string(6) "Denton" ["locationstate"]=> string(2) "TX" ["instructorname"]=> string(9) "Test" ["instructorlastname"]=> string(9) "Test" ["ahainstructorid"]=> string(11) "04112392307" } NULL NULL FPDF error: Some data has already been output, can't send PDF file (output started at /home/alwaysc/public_html/admin/cardprinting_print3cards.php:1)

Okay, I found some of my errors :slight_smile:

See the below corrections:

Change

$record = $row_rsCourseStudents[($i * 3) + $j];

To

$record = $row_rsCourseStudents[$i + $j];

and change

for ($j = 0; $j < 3; $j++)

To

for ($j = 0; $j < 3 && isset($row_rsCourseStudents[$i + $j]); $j++)

Here is my test code (just to prove it out)

<?php
require_once('fpdf.php');
require_once('fpdi.php');

//Setup
$locationname = 'Home';
$coursenumber = '325';
$row_rsCourseStudents = array();
$row_rsCourseStudents[] = array(
	'studentsname'=>'Student 1',
	'studentlastname'=>'LastName',
	'instructorname'=>'Teacher 1',
	'instructorlastname' => 'LastName',
	'ahainstructorid' => '123',
	'coursedate' => '2013-09-12'
);
$row_rsCourseStudents[] = array(
	'studentsname'=>'Student 2',
	'studentlastname'=>'LastName',
	'instructorname'=>'Teacher 1',
	'instructorlastname' => 'LastName',
	'ahainstructorid' => '123',
	'coursedate' => '2013-09-12'
);
$row_rsCourseStudents[] = array(
	'studentsname'=>'Student 3',
	'studentlastname'=>'LastName',
	'instructorname'=>'Teacher 2',
	'instructorlastname' => 'LastName',
	'ahainstructorid' => '123',
	'coursedate' => '2013-09-12'
);
$row_rsCourseStudents[] = array(
	'studentsname'=>'Student 4',
	'studentlastname'=>'LastName',
	'instructorname'=>'Teacher 1',
	'instructorlastname' => 'LastName',
	'ahainstructorid' => '123',
	'coursedate' => '2013-09-12'
);
$row_rsCourseStudents[] = array(
	'studentsname'=>'Student 5',
	'studentlastname'=>'LastName',
	'instructorname'=>'Teacher 1',
	'instructorlastname' => 'LastName',
	'ahainstructorid' => '123',
	'coursedate' => '2013-09-12'
);
$row_rsCourseStudents[] = array(
	'studentsname'=>'Student 6',
	'studentlastname'=>'LastName',
	'instructorname'=>'Teacher 2',
	'instructorlastname' => 'LastName',
	'ahainstructorid' => '123',
	'coursedate' => '2013-09-12'
);
$row_rsCourseStudents[] = array(
	'studentsname'=>'Student 7',
	'studentlastname'=>'LastName',
	'instructorname'=>'Teacher 1',
	'instructorlastname' => 'LastName',
	'ahainstructorid' => '123',
	'coursedate' => '2013-09-12'
);
$row_rsCourseStudents[] = array(
	'studentsname'=>'Student 8',
	'studentlastname'=>'LastName',
	'instructorname'=>'Teacher 1',
	'instructorlastname' => 'LastName',
	'ahainstructorid' => '123',
	'coursedate' => '2013-09-12'
);

$pdf= new fpdi();
//$pagecount = $pdf->setSourceFile("pdfcard/pdfs/3Cards.pdf");
//$tplidx = $pdf->ImportPage(1);
for ($i = 0; $i < sizeof($row_rsCourseStudents); $i+=3) {
	/* first page starts here */
	$pdf->addPage();
	//$pdf->useTemplate($tplidx,0,0,210);
	$pdf->SetFont('Arial','',12);

	for ($j = 0; $j < 3 && isset($row_rsCourseStudents[$i + $j]); $j++) // loop through the 3 records we need to process
	{
		$record = $row_rsCourseStudents[$i + $j];

		$pdf->SetXY(85, 5 + ($j * 20));
		$pdf->Cell(0,0,'');

		$pdf->SetFont('Arial','',9);
		$pdf->SetXY(125, 27 + ($j * 20));
		$pdf->Cell(0,0,'SCHOOL NAME');

		$pdf->SetXY(165, 27 + ($j * 20));
		$pdf->Cell(0,0,'SAMPLENUMBER');


		$pdf->SetXY(125, 36 + ($j * 20));
		$pdf->Cell(0,0,'citY,STATE');

		$pdf->SetXY(158, 36 + ($j * 20));
		$pdf->Cell(25,0,'1-855-555-5555',0,1,"R");


		$pdf->SetFont('Arial','',11);

		$pdf->SetXY(15, 47 + ($j * 20));
		$pdf->Cell(58,0,$record['studentsname'] . ' ' . $record['studentlastname'],0,1,"C");

		$pdf->SetFont('Arial','',9);
		$pdf->SetXY(135, 54 + ($j * 20));
		$pdf->Cell(45,0,$locationname. ' ' .$coursenumber,0,1,"R");


		$pdf->SetXY(120, 60 + ($j * 20));
		$pdf->Cell(30,0,$record['instructorname'] . ' '. $record['instructorlastname'],0,1,"L");
//aha instructor id
		$pdf->SetXY(135, 60 + ($j * 20));
		$pdf->Cell(45,0,$record['ahainstructorid'],0,1,"R");

//course date
		$coursedate = date('F Y',strtotime($record['coursedate']));
		$expdate = strtotime ('+2 years' , strtotime( $coursedate ) ) ;
		$expdate = date('F Y', $expdate);
		$pdf->SetXY(30, 64 + ($j * 20));
		$pdf->Cell(20,0,$coursedate,0,1,"C");

// coursedate plus 2 years
		$pdf->SetXY(72, 64 + ($j * 20));
		$pdf->Cell(20,0,$expdate,0,1,"C");
	}
}

$pdf->Output("temp.pdf", "I");
$pdf->closeParsers();

Ok done.
here are the results now.
Feel free to ignore me. :slight_smile:


int(1) array(14) { ["studentsid"]=> string(4) "2103" ["studentsname"]=> string(10) "Jon" ["studentlastname"]=> string(7) "Doe" ["scheduledcoursesid"]=> string(6) "100650" ["studentemddress"]=> string(22) "test@gmail.com" ["scheduledid"]=> string(6) "100650" ["coursetypename"]=> string(27) "Provider 1 " ["coursedate"]=> string(10) "2013-09-14" ["locationname"]=> string(42) "Hampton Inn" ["locationcity"]=> string(9) "Center1" ["locationstate"]=> string(2) "TX" ["instructorname"]=> string(9) "Jimmy" ["instructorlastname"]=> string(9) "Hernandez" ["instructorid"]=> string(11) "032432432" }

Comment out the var_dump lines now, so it attempts to generate the PDF

I did and now i get one student and the other lines dont generate. Before it would fill out the other cards except the student name, now i only get the first card. sorry. :frowning:

Can you post your complete code now? I feel there may be a disconnect in what I think you have and what you actually have. My test code works as expected.

Did you also ensure you are getting multiple students back instead of a single student by altering the student query?

Sending you a PM

Perfect, thanks! We definitely had a disconnect. So here are the changes I need you to make.

Find the following:

	$row_rsCourseStudents = array();
	while ($row = mysql_fetch_assoc($rsCourseStudents))
		$row_rsCourseStudents[] = $row;
	$totalRows_rsCourseSudents = mysql_num_rows($rsCourseStudents);

Change it to

	$row_rsCourseStudents = mysql_fetch_assoc($rsCourseStudents);

Next find this line:

for ($i = 0; $i < sizeof($row_rsCourseStudents); $i+=3) {

Replace it with

for ($i = 0; $i < sizeof($myprintinglist); $i+=3) {

Next find these lines:

	for ($j = 0; $j < 3 && isset($row_rsCourseStudents[$i + $j]); $j++)
	{
		$record = $row_rsCourseStudents[$i + $j];

Replace them with

	for ($j = 0; $j < 3 && isset($myprintinglist[$i + $j]); $j++)
	{
		$record = $myprintinglist[$i + $j];

Last but not least, find the following:

		$pdf->SetXY(120, 60 + ($j * $spacing));
		$pdf->Cell(30,0,$row_rsCourseStudents['instructorname'] . ' '. $row_rsCourseStudents['instructorlastname'],0,1,"L");
//aha instructor id
		$pdf->SetXY(135, 60 + ($j * $spacing));
		$pdf->Cell(45,0,$row_rsCourseStudents['ahainstructorid'],0,1,"R");

//course date
		$coursedate = date('F Y',strtotime($row_rsCourseStudents['coursedate']));

Replace it with

		$pdf->SetXY(120, 60 + ($j * $spacing));
		$pdf->Cell(30,0,$record['instructorname'] . ' '. $record['instructorlastname'],0,1,"L");
//aha instructor id
		$pdf->SetXY(135, 60 + ($j * $spacing));
		$pdf->Cell(45,0,$record['ahainstructorid'],0,1,"R");

//course date
		$coursedate = date('F Y',strtotime($record['coursedate']));

Save it and try running it (crossing my fingers that this solves it).

WOW IT WORKED!!!
YOU are a life saver.
I definately need some help with arrays, among other things.
Cant thank you enough.