title: Fpdf add another page when data rows reach the end of first page
body: <p>I am trying to write a PHP script that uses FPDF to produce a PDF document. So far I am able to produce a PDF but only when the number of rows returned from my MySQL query are less than the page height.</p>
  
  <p>If the number of rows returned are greater than the first page can accommodate the remaining rows jump to a second page but the data is allover the place, columns are not aligning and they seam to stepdown as each page to produced.</p>
  
  <p>I know I need to put some sort of line/row count in place and if the line/row count is reached, start a new page but heres where I am totally a at blank with my knowledge even after reading many posts and documents on how this is done.</p>
  
  <p>The code I have is:</p>
  
  <pre><code>class PDF extends FPDF
  {
  
  // Page footer
  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,'C');
  }
  }
  
  $pdf=new FPDF();
  $pdf-&gt;AliasNbPages();
  $pdf-&gt;AddPage('L');
  
  $pdf-&gt;SetFont('Arial', 'B', 18);
  $pdf-&gt;Text(230, 18, 'iMaint');
  
  $pdf-&gt;SetFont('Arial', 'B', 18);
  $pdf-&gt;Text(250, 18, 'Jobsheet');
  
  $pdf-&gt;SetY(28);
  $pdf-&gt;SetX(10);
  $pdf-&gt;SetFont('Arial', '', 11);
  $pdf-&gt;Text(10, 28, 'Jobsheet date:');
  
  $pdf-&gt;SetY(8);
  $pdf-&gt;SetX(37); 
  $pdf-&gt;SetFont('Arial', '', 11);
  $pdf-&gt;cell(10,38, $ToDay);
  
  $pdf-&gt;SetY(13);
  $pdf-&gt;SetX(10); 
  $pdf-&gt;SetFont('Arial', '', 11);
  $pdf-&gt;cell(10,38, 'Audit date:');
  
  $pdf-&gt;SetY(13);
  $pdf-&gt;SetX(37); 
  $pdf-&gt;SetFont('Arial', '', 11);
  $pdf-&gt;cell(10,38, date("d-m-Y", strtotime($row_RoomAudit['CompStamp'])));
  
  $pdf-&gt;SetFont('Arial', '', 12);
  $pdf-&gt;Text(240.5, 28, 'Hotel ID:');
  
  $pdf-&gt;SetY(10);
  $pdf-&gt;SetX(183.2);
  $pdf-&gt;SetFont('Arial', 'B', 18);
  $pdf-&gt;Text(10, 18, 'Room:');
  
  $pdf-&gt;SetFont('Arial', '', 12);
  $pdf-&gt;SetY(23);
  $pdf-&gt;SetX(260);    
  $pdf-&gt;cell(14,8, $_SESSION['hotel']);
  
  $pdf-&gt;SetY(12);
  $pdf-&gt;SetX(30);
  $pdf-&gt;SetFont('Arial', 'B', 18);
  $pdf-&gt;cell(14,8, $row_RoomAudit['Room']);
  
  $pdf-&gt;Ln(10);
  
  //Fields Name position
  $Y_Fields_Name_position = 40;
  //Table position, under Fields Name
  $Y_Table_Position = 46;
  
  $pdf-&gt;SetFillColor(232,232,232);
  $pdf-&gt;SetFont('Arial','B',11);
  $pdf-&gt;SetY($Y_Fields_Name_position);
  $pdf-&gt;SetX(10);
  $pdf-&gt;Cell(32,6,'Seq',1,0,'L',1);
  $pdf-&gt;SetX(32);
  $pdf-&gt;Cell(130,6,'Item',1,0,'L',1);
  $pdf-&gt;SetX(130);
  $pdf-&gt;Cell(155,6,'Job description',1,0,'L',1);
  
  $pdf-&gt;Ln();
  
  //Initialize the 3 columns and the total
  $column_seq = "";
  $column_seq_header = "";
  $column_job_description = "";
  $column_completed = "";
  $column_engineer = "";
  foreach ($row_RoomAudit as $key =&gt; $val) {
       if (strpos($val, '1') !== FALSE &amp;&amp; substr( $key, 0, 3)=='Seq' ){
           mysql_select_db($database_iMaint, $iMaint);
          $query_QuestionLookup = sprintf("SELECT SeqHeader, SeqText FROM SequenceNo WHERE SeqID = '".$key."'");
          $QuestionLookup = mysql_query($query_QuestionLookup, $iMaint) or die(mysql_error());
          $row_QuestionLookup = mysql_fetch_assoc($QuestionLookup);
          $totalRows_QuestionLookup = mysql_num_rows($QuestionLookup);
  
          $seq = $key;
          $Seq_header = $row_QuestionLookup['SeqHeader'];
          $jobdescription = $row_QuestionLookup['SeqText'];
  
          $column_seq = $column_seq.$seq."\n";
          $column_seq_header = $column_seq_header.$Seq_header."\n";
          $column_job_description =   $column_job_description.$jobdescription."\n";
  
          $pdf-&gt;SetFont('Arial','',8);
          $pdf-&gt;SetY($Y_Table_Position);
          $pdf-&gt;SetX(10);
          $pdf-&gt;MultiCell(22,6,$column_seq,1);
          $pdf-&gt;SetY($Y_Table_Position);
          $pdf-&gt;SetX(32);
          $pdf-&gt;MultiCell(98,6,$column_seq_header,1);
          $pdf-&gt;SetY($Y_Table_Position);
          $pdf-&gt;SetX(130);
          $pdf-&gt;MultiCell(155,6,$column_job_description,1);
      }
  }
  
  
  $i = 0;
  $pdf-&gt;SetY($Y_Table_Position);
  while ($i &lt; $totalRows_RoomAudit)
  {
  $pdf-&gt;SetX(10);
  $pdf-&gt;MultiCell(184,6,'',1);
  $i = $i +1;
  }
  
  $pdf-&gt;Output();
  </code></pre>
  
  <p>Can anyone offer me some help no how to deal with displaying the remaining rwos of data on the second or third and so on pages.</p>
  
  <p>Many thanks in advance for your time.</p>
  
  <p>Cheers.</p>