user3660378
user3660378

Reputation:

HTML/FPDF Table

I am working on printing this report to pdf:

goodReport

But all I get is this:

badReport

In this report, every student has a record in the columns Exam, Progress Report, Quiz, and Project.

Example Data:

enter image description here

Here is the part of my code:

while($row = mysql_fetch_assoc($sql_criteria)){
    $criteria[] = $row['criteria'];
    $pdf->SetFont('Arial','',9);
    $pdf->Cell(35,5,$row['criteria'],1,'','C');
}
    $pdf->Cell(35,5,'Grade',1,0,'C');
    $pdf->Cell(35,5,'Remark',1,0,'C');
    $pdf->SetFont('Arial','',9);
    $pdf->Ln();
while($row = mysql_fetch_array($sql)){
    $criteria_array = implode(" ", $criteria);
    $query_rec = mysql_query("SELECT equivalent FROM tb_student_record WHERE instructor_id = '$inst_id' AND criteria = '$criteria_array' AND description = '$desc' AND subj_code = '$code' AND term = '$term'");
    $record = mysql_fetch_array($query_rec);
    $name = $row['stud_name'];
    $course = $row['course_and_year'];
    $pdf->SetFont('Arial','',9);
    $pdf->Cell(1);
    $pdf->Cell(40,4,$name,1);
    $pdf->Cell(20,4,$course,1,0,'C');
    $pdf->Cell(5,4,$record['equivalent'],1,0,'C');
    $pdf->Ln();
}

So if there is any or something wrong with it kindly... Please point it out guys.. Any help will appreciated thanks in advance

Upvotes: 2

Views: 1035

Answers (1)

Logan Wayne
Logan Wayne

Reputation: 5991

  • You only try to display three columns per row in your code
  • We have to run through all the criteria to show the necessary data to display

Lets say $criteria is an array (remove the implode() part):

$criteria = array("Exam", "Progress Report", "Quiz", "Project");

Then run them all and bind it to your query:

$pdf->SetFont('Arial','',9); /* SET FONT TO ARIAL WITH FONT SIZE OF 9 */

while($row = mysql_fetch_array($sql)){ /* RUN THROUGH EACH STUDENT */

  $pdf->Cell(1);
  $pdf->Cell(40,4,$row['stud_name'],1); /* DISPLAY THE STUDENT'S NAME */
  $pdf->Cell(20,4,$row['course_and_year'],1,0,'C'); /* DISPLAY THE COURSE AND YEAR */

  for($x = 0; $x < count($criteria); $x++){ /* RUN ALL FOUR CRITERIAS */

    $query_rec = mysql_query("SELECT equivalent FROM tb_student_record WHERE instructor_id = '$inst_id' AND criteria = '".$criteria[$x]."' AND description = '$desc' AND subj_code = '$code' AND term = '$term'");
    $record = mysql_fetch_array($query_rec);
    $pdf->Cell(5,4,$record['equivalent'],1,0,'C'); /* DISPLAY THE SCORE FOR THE EQUIVALENT CRITERIA */

  } /* END OF FOR LOOP */

  $pdf->Ln(); /* NEW LINE */

} /* END OF WHILE LOOP; RUNNING THROUGH ALL THE STUDENTS */

And by the way, if you have time, consider using mysqli_* for your projects, rather than using the deprecated mysql_*.

Upvotes: 2

Related Questions