title: FPDF: How to limit the fetch data so footer will not add to next page
body: <p>How can I add a limitation on the output so that the footer will not go to next page?</p>
  
  <pre><code>class myPDF extends FPDF{
  
      function header(){
          $dates = new DateTime();
          $date2 = $dates-&gt;format('Y');
          $date=$_POST['month'];
          $this-&gt;SetFont('Arial','B',14);
          $this-&gt;Cell(189,5,'ABSTRACT OF COMMUNITY TAX CERTIFICATES',0,0,'C');
          $this-&gt;Ln();
          $this-&gt;SetFont('Times','',13);
          $this-&gt;Cell(189,10,'For the month of '.$date.' '.$date2,0,0,'C');
          $this-&gt;Ln(20);
      }
      function headerTable(){
          $this-&gt;SetTextColor(136,0,0);
          $this-&gt;SetFont('Times','B',10);
          $this-&gt;Cell(30,8,'Date',1,0,'C');
          $this-&gt;Cell(30,8,'CTC No.',1,0,'C');
          $this-&gt;Cell(60,8,'Name',1,0,'C');
          $this-&gt;Cell(23,8,'Individual',1,0,'C');
          $this-&gt;Cell(23,8,'Corporation',1,0,'C');
          $this-&gt;Cell(24,8,'Total',1,0,'C');
          $this-&gt;Ln();
      }
      function viewTable($db){
          $this-&gt;SetTextColor(0,0,0);
          $this-&gt;SetFont('Times','',10);
          $name = $_SESSION['name'];
          $repnumber=$_POST['id'];
          $stmt = $db-&gt;query("select * from tblctcab where cedrepnum='$repnumber' and username='$name' order by repdate asc");
          $count=0;
          while($data = $stmt-&gt;fetch(PDO::FETCH_OBJ)){
              $this-&gt;Cell(30,8,$data-&gt;repdate,1,0,'C');
              $this-&gt;Cell(30,8,$data-&gt;ctcnumber,1,0,'C');
              $this-&gt;Cell(60,8,$data-&gt;cedlname.', '.$data-&gt;cedfname,1,0,'C');
              $this-&gt;Cell(23,8,$data-&gt;totalampa,1,0,'C');
              $this-&gt;Cell(23,8,'',1,0,'C');
              $this-&gt;Cell(24,8,$data-&gt;totalampa,1,0,'C');
              $this-&gt;Ln();
              }
          $stmts = $db-&gt;query("select * from tblctcc where cedrepn='$repnumber' and username='$name' order by rpdate asc");
          $count=0;
          while($dat = $stmts-&gt;fetch(PDO::FETCH_OBJ)){
                  $this-&gt;Cell(30,8,$dat-&gt;rpdate,1,0,'C');
                  $this-&gt;Cell(30,8,$dat-&gt;ctcnum,1,0,'C');
                  $this-&gt;Cell(60,8,$dat-&gt;comfname,1,0,'C');
                  $this-&gt;Cell(23,8,'',1,0,'C');
                  $this-&gt;Cell(23,8,$dat-&gt;totalampas,1,0,'C');
                  $this-&gt;Cell(24,8,$dat-&gt;totalampas,1,0,'C');
                  $this-&gt;Ln();
               }
          $dbs=new mysqli('localhost' , 'root' , '', 'tres');
          $repdate=$_POST['id'];
          $ctcab = $dbs-&gt;query("select sum(totalampa) as totalampa from tblctcab where cedrepnum='$repnumber'  and username='$name'");
          $data = $ctcab-&gt;fetch_assoc();
          $totalab = $data['totalampa'];
          $ctcc = $dbs-&gt;query("select sum(totalampas) as totalampas from tblctcc where cedrepn='$repnumber' and username='$name'");
          $datac = $ctcc-&gt;fetch_assoc();
          $totalcc = $datac['totalampas'];
          $overall = $totalab + $totalcc;
  
          $this-&gt;SetTextColor(136,0,0);
          $this-&gt;SetFont('Times','B',10);
          $this-&gt;Cell(120,8,$_POST['id'],1,0,'C');
          //$this-&gt;Cell(55,8,'TOTAL',1,0,'C');
          $this-&gt;Cell(23,8,number_format($totalab),1,0,'C');
          $this-&gt;Cell(23,8,number_format($totalcc),1,0,'C');
          $this-&gt;Cell(24,8,number_format($totalab),1,0,'C');
          $this-&gt;Ln();
  
          $this-&gt;SetTextColor(0,0,0);
          $this-&gt;SetFont('Times','',10);
          $this-&gt;Cell(95,8,'',0,0,'C');
          $this-&gt;Cell(95,8,'',0,0,'C');
          $this-&gt;Ln();
          $this-&gt;Cell(95,5,'Prepared By:',0,0,'L');
          $this-&gt;Cell(95,5,' Certified By:',0,0,'L');
          $this-&gt;Ln();
  
          $this-&gt;SetFont('Times','',10);
          $this-&gt;Cell(95,5,$_SESSION['name'],0,0,'C');
          $this-&gt;Cell(95,5,'CONNIE',0,0,'C');
          $this-&gt;Ln();
          $this-&gt;Cell(95,5,$_SESSION['position'],0,0,'C');
          $this-&gt;Cell(95,5,'Treasurer',0,0,'C');
          $this-&gt;Ln();
      }
      function footer(){
          $this-&gt;SetY(-15);
          $this-&gt;SetFont('Arial','',8);
          $this-&gt;Cell(0,10,'Page '.$this-&gt;PageNo().'/{nb}',0,0,'R');
      }
  
  }
  $pdf = new myPDF();
  
  $pdf-&gt;AliasNbPages();
  
  $pdf-&gt;AddPage('','A4',0);
  
  $pdf-&gt;headerTable();
  
  $pdf-&gt;viewTable($db);
  
  $pdf-&gt;Output();
  </code></pre>