title: FPDF Multiply Table PHP PDO
body: <p>I need to print the curriculum data's in PDF file. On the Front-End got no problem.</p>
  
  <p><a href="https://i.stack.imgur.com/eadyD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eadyD.png" alt="enter image description here"></a></p>
  
  <p>But applying the same code on FPDF is kinda hard for me. I need to display the curriculum data's like on my front-end. I made this so far.</p>
  
  <p><a href="https://i.stack.imgur.com/9Qmky.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9Qmky.png" alt="enter image description here"></a></p>
  
  <p>And here is the whole code for that script.</p>
  
  <pre><code>&lt;?php
  include "../../include/student_session.php";
  $user_id = $_SESSION['student'];
  $stmt = $DB_con-&gt;prepare("SELECT *, h.campus as 'h.campus', k.batch as 'k.batch', j.id as 'j.id', a.department_id as 'dept' FROM student_info a
                                      INNER JOIN section b ON b.id = a.section_id
                                      INNER JOIN course c ON c.id = a.course_id
                                      INNER JOIN year_tbl d ON d.id = a.year_id
                                      INNER JOIN batch_tbl e ON e.id = a.batch_id
                                      INNER JOIN department f ON f.id = a.department_id
                                      INNER JOIN scholarship g ON g.id = a.scholarship_id
                                      INNER JOIN campus h ON h.id = a.campus
                                      INNER JOIN school_year i ON i.id = a.sy_id
                                      INNER JOIN curriculum j ON j.department_id = a.department_id AND j.course_id = a.course_id
                                      INNER JOIN batch_tbl k ON k.id = j.batch_id
                                      WHERE a.id=:id");
  $stmt-&gt;execute(array(":id"=&gt;$user_id));
  $userRow=$stmt-&gt;fetch(PDO::FETCH_ASSOC);
  require('fpdf.php');
  
  class PDF extends FPDF {
      function Header() {
          // Logo
  
          $this-&gt;Image('../../login-folder/assets/img/logo_ac_long.png',68,10,80);
  
      }
      function Footer() {
          // Position at 1.5 cm from bottom
          $this-&gt;SetY(-15);
          // Arial italic 8
          $this-&gt;SetFont('Arial','I',8);
          // Page number
          $this-&gt;Cell(0,10,'Page '.$this-&gt;PageNo().'/{nb}',0,0,'R');
          //$this-&gt;Line(20, 45, 210-20, 45); // 20mm from each edge
          $this-&gt;GetY(15); 
          $x=$this-&gt;GetY(15); 
          //$this-&gt;Line(160,250,296-100,250); 
  
          $this-&gt;Line(10,285,200,285); 
          $this-&gt;Ln(); 
          $fech = time(); 
          $fecha = date( "m/d/y" ,$fech); 
          $this-&gt;Text(10,288,$fecha);
      }
  }
  
  
  $pdf = new PDF();
  $pdf-&gt;AliasNbPages();
  $pdf-&gt;AddPage();
  $pdf-&gt;SetFont('Times','',12);
  
  $pdf-&gt;Ln(30);
  $pdf-&gt;Cell(10);
  $pdf-&gt;SetFont('Arial','', 8);
  $pdf-&gt;Cell(30,5,'Student Number: '.$userRow['student_no']);
  $pdf-&gt;Cell(70);
  $pdf-&gt;Cell(30,5,'Section Block : '.$userRow['section_code']);
  
  $pdf-&gt;Ln(6);
  $pdf-&gt;Cell(10);
  $pdf-&gt;Cell(30,5,'Reference No  : ----------');
  $pdf-&gt;Cell(70);
  $pdf-&gt;Cell(30,5,'School Year   : '.$userRow['school_year']);
  
  $pdf-&gt;Ln(6);
  $pdf-&gt;Cell(10);
  $pdf-&gt;Cell(30,5,'Name          : '.$userRow['student_name']);
  $pdf-&gt;Cell(70);
  $pdf-&gt;Cell(30,5,'Semester      : '.$userRow['semester']);
  
  $pdf-&gt;Ln(6);
  $pdf-&gt;Cell(10);
  $pdf-&gt;Cell(30,5,'Course          : '.$userRow['course_code']);
  $pdf-&gt;Cell(70);
  $pdf-&gt;Cell(30,5,'Year            : '.$userRow['year']);
  
  $pdf-&gt;Ln(6);
  $pdf-&gt;Cell(10);
  $pdf-&gt;Cell(30,5,'Curriculum    : Ver.'.$userRow['j.id'].', '.$userRow['k.batch']);
  $pdf-&gt;Cell(70);
  $pdf-&gt;Cell(30,5,'Status        : Currently Enrolled');
  
  $pdf-&gt;Ln(6);
  $pdf-&gt;Cell(10);
  $pdf-&gt;Cell(30,5,'Campus        : '.$userRow['campus']);
  $pdf-&gt;Cell(70);
  $pdf-&gt;Cell(30,5,'Scholarship   : '.$userRow['scholarship_type']);
  $stmt5 = $DB_con-&gt;prepare("SELECT *,a.id as 'a.id', b.year_id as 'b.year_id' FROM year_tbl a INNER JOIN subjects b ON b.year_id = a.id AND department_id = :dept group by a.id order by a.id asc; ");
  $stmt5-&gt;bindparam(":dept", $userRow['dept']);
  $stmt5-&gt;execute();
  $userRow5=$stmt5-&gt;fetchAll(PDO::FETCH_ASSOC);
  if($stmt5-&gt;rowCount() &gt; 0) {
      foreach ($userRow5 as $key) {
              $pdf-&gt;Ln(10);
              $pdf-&gt;Cell(10);
              $pdf-&gt;SetFont('Arial', 'B', 12);
              $pdf-&gt;Cell(30,5,$key['year']. ' - ' .$key['semester']);
  
              //set initial y axis position per page
              $y_axis_initial = 86;
              //Set Row Height
              $row_height = 6;
  
              //print column titles for the actual page
              $pdf-&gt;SetFillColor(255, 255, 255);
              $pdf-&gt;SetFont('Arial', '', 8);
  
              $pdf-&gt;SetY($y_axis_initial);
              $pdf-&gt;SetX(12);
  
  
              $pdf-&gt;Cell(30, 6, 'Subject Code', 1, 0, 'C', 1);
              $pdf-&gt;Cell(10, 6, 'Units', 1, 0, 'C', 1);
              $pdf-&gt;Cell(12, 6, 'Prelims', 1, 0, 'C', 1);
              $pdf-&gt;Cell(14, 6, 'Remarks', 1, 0, 'C', 1);
              $pdf-&gt;Cell(12, 6, 'Midterm', 1, 0, 'C', 1);
              $pdf-&gt;Cell(14, 6, 'Remarks', 1, 0, 'C', 1);
              $pdf-&gt;Cell(12, 6, 'Finals', 1, 0, 'C', 1);
              $pdf-&gt;Cell(14, 6, 'Remarks', 1, 0, 'C', 1);
              $pdf-&gt;Cell(12, 6, 'Average', 1, 0, 'C', 1);
              $pdf-&gt;Cell(14, 6, 'Equivalent', 1, 0, 'C', 1);
              $pdf-&gt;Cell(40, 6, 'Instructor', 1, 0, 'C', 1);
  
              $y_axis = $y_axis_initial  + $row_height;
              //initialize counter
              $i = 0;
  
              //Set maximum rows per page
              $max = 25;
  
              $stmt2 = $DB_con-&gt;prepare("SELECT *, d.id as 'b.section_id', c.id as 'b.subject_id', c.subject_code as 'c.subject_code', a.year_id as 'yid', a.batch_id as 'bid', (lec_units + lab_units) as 'total'  FROM student_info a
                                      INNER JOIN curriculum b ON b.department_id = a.department_id AND b.batch_id = a.batch_id AND b.course_id = a.course_id
                                      INNER JOIN curriculum_subjects f ON f.curriculum_id = b.id
                                      INNER JOIN subjects c ON c.id = f.subject_id AND c.year_id = :yid
                                      INNER JOIN section d ON d.id = a.section_id
                                      INNER JOIN batch_tbl e ON e.id = a.batch_id
  
                                      WHERE a.student_no = :value");
              $stmt2-&gt;bindparam(":value", $userRow['student_no']);
              $stmt2-&gt;bindparam(":yid", $key['a.id']);
              $stmt2-&gt;execute();
              $userRow2=$stmt2-&gt;fetchAll(PDO::FETCH_ASSOC);
              if ($stmt2-&gt;rowCount() &gt; 0) {
                  foreach ($userRow2 as $key2) {
  
                      if ($i == $max) {
                          $pdf-&gt;AddPage();
  
                          //print column titles for the current page
                          $pdf-&gt;SetY($y_axis_initial);
                          $pdf-&gt;SetX(33);
  
                          //$pdf-&gt;Cell(30, 6, 'Resident', 1, 0, 'L', 1);
  
                          $pdf-&gt;Cell($pdf-&gt;GetStringWidth('Subject Code')+3, 6, 'Subject Code', 1, 0, 'C', 1);
                          $pdf-&gt;Cell($pdf-&gt;GetStringWidth('Units')+3, 6, 'Units', 1, 0, 'L', 1);
                          $pdf-&gt;Cell($pdf-&gt;GetStringWidth('Prelims')+3, 6, 'Prelims', 1, 0, 'L', 1);
                          $pdf-&gt;Cell($pdf-&gt;GetStringWidth('Remarks')+3, 6, 'Remarks', 1, 0, 'L', 1);
                          $pdf-&gt;Cell($pdf-&gt;GetStringWidth('Midterm')+3, 6, 'Midterm', 1, 0, 'L', 1);
                          $pdf-&gt;Cell($pdf-&gt;GetStringWidth('Remarks')+3, 6, 'Remarks', 1, 0, 'L', 1);
                          $pdf-&gt;Cell($pdf-&gt;GetStringWidth('Finals')+3, 6, 'Finals', 1, 0, 'L', 1);
                          $pdf-&gt;Cell($pdf-&gt;GetStringWidth('Remarks')+3, 6, 'Remarks', 1, 0, 'L', 1);
                          $pdf-&gt;Cell($pdf-&gt;GetStringWidth('Average')+3, 6, 'Average', 1, 0, 'L', 1);
                          $pdf-&gt;Cell($pdf-&gt;GetStringWidth('Equivalent')+3, 6, 'Equivalent', 1, 0, 'L', 1);
                          $pdf-&gt;Cell($pdf-&gt;GetStringWidth('Instructor')+3, 6, 'Instructor', 1, 0, 'L', 1);
                          //Go to next row
                          $y_axis = $y_axis + $row_height;
  
                          //Set $i variable to 0 (first row)
                          $i = 0;
                      }
                      $semester = $key2['subject_code'];
                      $pdf-&gt;SetY($y_axis);
                      $pdf-&gt;SetX(12);
                      $pdf-&gt;Cell(30, 6, $semester, 1, 0, 'C', 1);
                      $pdf-&gt;Cell(10, 6, '', 1, 0, 'C', 1);
                      $pdf-&gt;Cell(12, 6, '', 1, 0, 'C', 1);
                      $pdf-&gt;Cell(14, 6, '', 1, 0, 'C', 1);
                      $pdf-&gt;Cell(12, 6, '', 1, 0, 'C', 1);
                      $pdf-&gt;Cell(14, 6, '', 1, 0, 'C', 1);
                      $pdf-&gt;Cell(12, 6, '', 1, 0, 'C', 1);
                      $pdf-&gt;Cell(14, 6, '', 1, 0, 'C', 1);
                      $pdf-&gt;Cell(12, 6, '', 1, 0, 'C', 1);
                      $pdf-&gt;Cell(14, 6, '', 1, 0, 'C', 1);
                      $pdf-&gt;Cell(40, 6, '', 1, 0, 'C', 1);
                      //Go to next row
                      $y_axis = $y_axis + $row_height;
                      $i = $i + 1;
                  }
                  $pdf-&gt;Output();
              }
  
      }
  //    $pdf-&gt;Ln(10);
  //    $pdf-&gt;Cell(10);
  //    $pdf-&gt;SetFont('Arial','b', 8);
  //    $pdf-&gt;Cell(30,5,'NOTE: THIS IS NOT VALID WHEN THERE IS NO SIGNATURE OF REGISTAR OFFICE.');
  
  }
  ?&gt;
  </code></pre>
  
  <p><strong>What mistake did I do here? What I'm missing? I need help to achieve the front-end output like that.</strong></p>