title: How to repeat the table column header in each page
body: <p>I'm using FPDF to create a PDF file which the data is getting pulled from a MySQL database. And the table is getting created with two main column headers "User Name" and "Total Time Spent".</p>
  
  <pre><code>&lt;?php
  /**
   * Created by PhpStorm.
   * User: SiNUX
   * Date: 8/3/2017
   * Time: 2:44 PM
   */
  
  require('../Libraries/fpdf/fpdf.php');
  include_once ('../iConnect/handShake.php');
  
  class h4PDF extends FPDF{
      function Header(){
          $this-&gt;Image('../../images/logo.png', 10,6,30);
          $this-&gt;SetFont('Arial', 'B', 12);
          $this-&gt;Cell(80);
          $this-&gt;Cell(50, 10, 'Total Spent Time', 0, 0,'C');
          $this-&gt;Ln(10);
      }
  }
  
  $getTot = "SELECT userlogin.uName, SEC_TO_TIME(SUM(TIME_TO_SEC(timeSpent))) AS totTime FROM usertimetrack
             LEFT JOIN userlogin ON usertimetrack.usrId = userlogin.uId WHERE jDate = :jdate GROUP BY usrId";
  $getTotQuery = $dbConnect -&gt; prepare($getTot);
  $getTotQuery -&gt; bindParam('jdate', $_REQUEST["date"]);
  $getTotQuery -&gt; execute();
  
  $pdf = new h4PDF();
  $pdf-&gt;AddPage();
  
  $pdf-&gt;SetFont('Arial','', 14);
  $pdf-&gt;SetFillColor(255,0,0);
  $pdf-&gt;SetTextColor(255);
  $pdf-&gt;SetDrawColor(128,0,0);
  $pdf-&gt;SetLineWidth(.3);
  $pdf-&gt;SetFont('','B');
  
  $pdf-&gt;SetX(70);
  $pdf-&gt;Cell(40,6,'User Name',1,0,'C',1);
  $pdf-&gt;SetX(105);
  $pdf-&gt;SetX(110);
  $pdf-&gt;Cell(42,6,'Total Spent Time',1,0,'C',1);
  $pdf-&gt;Ln();
  
  $pdf-&gt;SetFillColor(224,235,255);
  $pdf-&gt;SetTextColor(0);
  $pdf-&gt;SetFont('');
  
  $fill = false;
  while ($getTotRow = $getTotQuery -&gt; fetch(PDO::FETCH_ASSOC)){
      $uName = $getTotRow["uName"];
      $totTime = $getTotRow["totTime"];
  
      $pdf-&gt;SetX(70);
      $pdf-&gt;Cell(40,6,$uName,'LR',0,'C',$fill);
      $pdf-&gt;SetX(105);
      $pdf-&gt;SetX(110);
      $pdf-&gt;Cell(42,6,$totTime ,'LR',0,'C',$fill);
      $pdf-&gt;Ln();
      $fill = !$fill;
  }
  $pdf-&gt;SetX(70);
  $pdf-&gt;Cell(82,0,'','T');
  
  $pdf-&gt;Output();
  </code></pre>
  
  <p>With the current code I can create the table but this code only prints the header of the table columns on the first page only actually at the beginning of the table and the rest will be filled with data which continues till the data ends. I wish to repeat these 2 header on each page at the beginning of the table on each page.</p>
  
  <p>I tried to do something like <a href="http://www.fpdf.org/en/script/script30.php" rel="nofollow noreferrer">this</a> script but ended up creating an infinity loop.</p>
  
  <p>I think I do have to do a manual data amount for the page, then turn off the auto page break, then check for the max data and then print the header if the table has reached it's max data amount. But I don't know how to plug that in to this code.</p>
  
  <p>Can some one please show me how to do this, I'm posting this after many attempts which failed or ended up me breaking the entire script.</p>
  
  <p>**UPDATE:**Thanks to kastriotcunaku I managed to solve my problem now my new code is as follows,</p>
  
  <pre><code>&lt;?php
  /**
   * Created by PhpStorm.
   * User: SiNUX
   * Date: 8/3/2017
   * Time: 2:44 PM
   */
  
  require('../Libraries/fpdf/fpdf.php');
  include_once ('../iConnect/handShake.php');
  
  class h4PDF extends FPDF{
      function Header(){
          $this-&gt;Image('../../images/logo.png', 10,6,30);
          $this-&gt;SetFont('Arial', 'B', 12);
          $this-&gt;Cell(80);
          $this-&gt;Cell(50, 10, 'Total Spent Time', 0, 0,'C');
          $this-&gt;Ln(10);
  
          $this-&gt;SetFont('Arial','', 14);
          $this-&gt;SetFillColor(255,0,0);
          $this-&gt;SetTextColor(255);
          $this-&gt;SetDrawColor(128,0,0);
          $this-&gt;SetX(74);
          $this-&gt;Cell(40,6,'User Name',1,0,'C',1);
          $this-&gt;SetX(109);
          $this-&gt;SetX(114);
          $this-&gt;Cell(42,6,'Total Spent Time',1,0,'C',1);
          $this-&gt;Ln();
      }
  }
  
  $getTot = "SELECT userlogin.uName, SEC_TO_TIME(SUM(TIME_TO_SEC(timeSpent))) AS totTime FROM usertimetrack
             LEFT JOIN userlogin ON usertimetrack.usrId = userlogin.uId WHERE jDate = :jdate GROUP BY usrId";
  $getTotQuery = $dbConnect -&gt; prepare($getTot);
  $getTotQuery -&gt; bindParam('jdate', $_REQUEST["date"]);
  $getTotQuery -&gt; execute();
  
  $pdf = new h4PDF();
  $pdf-&gt;AddPage();
  
  $pdf-&gt;SetFont('Arial','', 14);
  $pdf-&gt;SetFillColor(255,0,0);
  $pdf-&gt;SetTextColor(255);
  $pdf-&gt;SetDrawColor(128,0,0);
  $pdf-&gt;SetLineWidth(.1);
  $pdf-&gt;SetFont('','B');
  
  $pdf-&gt;SetFillColor(224,235,255);
  $pdf-&gt;SetTextColor(0);
  $pdf-&gt;SetFont('');
  
  $fill = false;
  while ($getTotRow = $getTotQuery -&gt; fetch(PDO::FETCH_ASSOC)){
      $uName = $getTotRow["jDate"];
      $totTime = $getTotRow["timeSpent"];
  
      $pdf-&gt;SetX(74);
      $pdf-&gt;Cell(40,6,$uName,'1',0,'C',$fill);
      $pdf-&gt;SetX(109);
      $pdf-&gt;SetX(114);
      $pdf-&gt;Cell(42,6,$totTime ,'1',0,'C',$fill);
      $pdf-&gt;Ln();
      $fill = !$fill;
  }
  
  $pdf-&gt;Output();
  </code></pre>
  
  <p>I removed the last line which was to be drawn after the while loop stops which actually was just leaving the end of the table with out a last line so I removed that and enable the borders of the cells and set the line width to 0.1 which made my table look much better.</p>