title: Excessive page break of pdf using fpdf
body: <p>I want to show data from a MySQL database in a table form. When the data exceeds the first page, the next row is written correctly on the next page. But every row after that is written to a new page. This means the first page looks fine, but the second page and beyond will contain one row only. How can I prevent this? Below is my code:</p>
  
  <pre><code>&lt;?php
  require('fpdf17/fpdf.php');
  require('db.php');
  
  //create a FPDF object
  $pdf=new FPDF();
  
  //set font for the entire document
  $pdf-&gt;SetFont('Times','B',20); //set font for the whole page (font family, style, size)
  $pdf-&gt;SetTextColor(0,0,0); //using RGB value
  
  //set up a page
  $pdf-&gt;AddPage('P');  //potrait orientation
  $pdf-&gt;SetDisplayMode('default'); //using 100 percent zoom and the viewer's default layout
  
  //insert an image
  $icon = "files/icon.png";
  $pdf-&gt;Cell (10);
  $pdf-&gt;Cell(60, 60, $pdf-&gt;Image($icon, $pdf-&gt;GetX(), $pdf-&gt;GetY(), 33.78), 0, 0, 'L', false);
  
  $pdf-&gt;SetFillColor(0,0,0);
  $pdf-&gt;SetFont('Times', '', 12);
  $pdf-&gt;SetXY(10, 30);
  $pdf-&gt;Cell(10);
  $pdf-&gt;Cell(30, 6, 'Retrieval Date' , 0, 0, '', 0);
  date_default_timezone_set("Asia/Kuala_Lumpur"); //set default time zone
  $pdf-&gt;Cell(30, 6, ': '.date("d/m/Y"), 0, 2, 'B', 0);
  
  //Set x and y position for the main text, reduce font size and write content
  $pdf-&gt;SetXY(20,40); //setting the position
  $pdf-&gt;SetFont('Times', 'BU', 14);
  $pdf-&gt;Write(12,'Absenteeism record for:');
  
  $fac = addslashes( filter_input( INPUT_GET,'fac',FILTER_SANITIZE_STRING ) );
  $data = "SELECT * FROM faculty WHERE fac_code LIKE '$_GET[fac]'";
  
  $result = $conn-&gt;query($data) or die("Error: ".mysqli_error($conn));
  while($ser=mysqli_fetch_array($result)){
  
      $fac_name = $ser['fac_name'];
      $pdf-&gt;SetFillColor(0,0,0);
      $pdf-&gt;SetFont('Times', '', 12);
      $pdf-&gt;SetY(50);
      $pdf-&gt;Cell(10);
      $pdf-&gt;SetX(20);
      $pdf-&gt;Cell(30, 6, 'FACULTY' , 0, 0, '', 0);
      $pdf-&gt;Cell(30, 6, ': '.$fac.'-'.' '.$fac_name, 0, 2, 'B', 0);
  }
  
  //start first table
  $pdf-&gt;SetFillColor(255,255,255);
  $pdf-&gt;SetFont('Times', 'B', 12);
  $pdf-&gt;SetXY(21,58);
  $pdf-&gt;Cell(10, 6, 'No.', 1, 0, 'L', 1);
  $pdf-&gt;Cell(25, 6, 'Matric no', 1, 0, 'L', 1);
  $pdf-&gt;Cell(45, 6, 'Name', 1, 0, 'L', 1);
  $pdf-&gt;Cell(31, 6, 'Programme', 1, 0, 'L', 1);
  $pdf-&gt;Cell(20, 6, 'Course', 1, 0, 'L', 1);
  $pdf-&gt;Cell(35, 6, 'Absenteeism %', 1, 0, 'L', 1);
  
  $row_height = 6;
  $y1_axis = 58;
  $y1_axis = $y1_axis + $row_height;
  $counter = 1;
  $fac = addslashes( filter_input( INPUT_GET,'fac',FILTER_SANITIZE_STRING ) );
  $data = "
      SELECT
          stud_matric, stud_name, fac_code, fac_name, group_group_code, prog_code, course_course_code,
          getid, SUM(studAtt_endTime - studAtt_startTime)/(course_contacthour_perWeek * 14) AS 'sum'
      FROM studentattendance";
  
  
  
  $result = $conn-&gt;query($data)  or die("Error: ".mysqli_error($conn));
  while($ser=mysqli_fetch_array($result)){
  
      $fac_name = $ser['fac_name'];
      $stud_matric = $ser['stud_matric'];
      $stud_name = $ser['stud_name'];
      $prog_code = $ser['prog_code'];
      $course_course_code = $ser['course_course_code'];
      $per= $ser['sum'];
  
      $pdf-&gt;SetFont('Times', '', 12);
      $pdf-&gt;SetXY(21, $y1_axis);
      $pdf-&gt;Cell(10, 6, $counter, 1, 0, 'L', 1);
      $pdf-&gt;Cell(25, 6, $stud_matric, 1, 0, 'L', 1);
      $pdf-&gt;Cell(45, 6, $stud_name, 1, 0, 'L', 1);
      $pdf-&gt;Cell(31, 6, $prog_code, 1, 0, 'L', 1);
      $pdf-&gt;Cell(20, 6, $course_course_code, 1, 0, 'L', 1);
      $pdf-&gt;Cell(35, 6, $per, 1, 0, 'L', 1);
      $pdf-&gt;Ln();
  
      $y1_axis = $y1_axis + $row_height;
      $counter++;
  }
  //end first table
  
  //Output the document
  $pdf-&gt;Output("$fac.pdf",'I'); 
  ?&gt; 
  </code></pre>