我正在使用FPDF库打印一个填充了从PDF数据库中检索到的数据的表。我希望这段代码一直运行到最后,并在表格中打印学生的数据。它正在为第一组完美地检索和打印数据,但对于其他组,它只打印表格并且不会填充它与数据。 这是我的代码。
session_start();
require ('../make_db_connection.php');
require ("../fpdf/fpdf.php");
$pdf=new FPDF('P','mm','A4');
$res = $conn->query("SELECT * FROM student_data");
$num=$res->num_rows;
while ($num > 0)
{
$pdf->AddPage();
if ($num != 0)
{
$row = $res->fetch_assoc();
$title=$row['title'];
$date=$row['sub_date'];
$supervisor=$row['supervisor'];
$res = $conn->query("SELECT name,roll_no,abstract FROM student_data WHERE title='".$title."' AND supervisor='".$supervisor."'");
}
$pdf->SetFillColor(232,232,232);
$pdf->SetMargins(30,0,20);
$pdf->SetFont('Times','B',14);
$pdf->Cell(0,10,'',0,1);
$pdf->Cell(0,7,"FYP Evaluation Sheet",0,1,'C');
$pdf->SetFont('Times','B',13);
$pdf->Cell(0,4,'',0,1);
$pdf->Cell(40,7,"GR#:",0,0,'L');
$pdf->Cell(30,7,"Project Title:",0,0,'L');
$pdf->SetFont('Times','',11);
$pdf->MultiCell(90,7,$title,'','L',FALSE);
//Table
$pdf->SetFont('Times','B',13);
$pdf->Cell(0,4,'',0,1);
$pdf->Cell(40,7,"Individuals:",0,0,'L');
$pdf->Cell(0,10,'',0,1);
$x=$pdf->GetX();
$y=$pdf->GetY();
$pdf->MultiCell(35,10, 'Reg#','LRTB','C',TRUE);
$pdf->SetXY($x+35,$y);
$pdf->MultiCell(70,10, 'Name','LTB','C', TRUE);
$pdf->SetXY($x+105,$y);
$pdf->MultiCell(50,10, 'Marks & Comments','LRTB','C', TRUE);
$pdf->MultiCell(0,0, '','R',FALSE);
$pdf->SetFont('Times','',10);
$x=$pdf->GetX();
$y=$pdf->GetY();
$row = $res->fetch_assoc();
$student1=$row['name'];
$student1_rollno=$row['roll_no'];
$num=$num-1;
$pdf->MultiCell(35,8,$student1_rollno,'LRB','C',0);
$pdf->SetXY($x+35,$y);
$pdf->MultiCell(70,8,$student1,'B','C', 0);
$pdf->SetXY($x+105,$y);
$pdf->MultiCell(50,8,'','LRB','L', 0);
$x=$pdf->GetX();
$y=$pdf->GetY();
$row = $res->fetch_assoc();
if($row)
{
$student2=$row['name'];
$student2_rollno=$row['roll_no'];
$pdf->MultiCell(35,8,$student2_rollno,'LRB','C',0);
$pdf->SetXY($x+35,$y);
$pdf->MultiCell(70,8,$student2,'B','C', 0);
$pdf->SetXY($x+105,$y);
$pdf->MultiCell(50,8,'','LRB','L', 0);
$num=$num-1;
}
$pdf->MultiCell(100,8, 'Note: Please fill the form and submit with name and signature.','','L', 0);
}
ob_end_clean();
$pdf->output();
我在这段代码中做错了什么?我无法弄清楚!