   <?php require 'funcs/conexion.php';
   require 'funcs/funcs.php';
   require ('fpdf/fpdf.php');
   date_default_timezone_set('America/Mexico_City');
   header("Content-Type: text/html;charset=utf-8");

       
   if (!empty($_GET))
               {
  $fi = $_GET['fi'];
  $ff = $_GET['ff'];
  $sql="SELECT COUNT(`ref_nombre`) as num,`ref_nombre` FROM `pacientes`,`referidos` where ref_id !=0 and `pac_fechaingreso` >= '$fi' and `pac_fechaingreso` <= '$ff' and pac_ref_id = ref_id GROUP by `ref_nombre` ORDER by num DESC";
  $resultado = mysqli_query($mysqli, $sql);
class PDF extends FPDF
{
   
   function Header()
   {
      //$this->Image("img/fi.jpg", 5, null, 200,30);
      $this->Image('img/logo.png', 150, 5, 40 );
      $this->Image('img/fondo.png', 10, 160, 180,90);
     
      $this->Ln(20);

   }
   function Footer()
   {
       $this->SetXY(120,238);
       $this->SetFont('Arial','B',10);
      $this->Cell(13,30, utf8_decode('Dra. Nelly Eugenia Robles Luján. C.P. 4412680'),0,0,'L');

      //Go to 1.5 cm from bottom
       $this->SetY(-40);
       //this->Image('img/fi.png', 5, 270, 200 );     
         

       $this->Image("img/fi.jpg", 5, null, 200,30);
       //Select Arial italic 8
       $this->SetFont('Arial','I',8);
       //Print current and total page numbers
       $this->Cell(0,10,utf8_decode('Página ').$this->PageNo().'/{nb}',0,0,'C');
   }
}

      $pdf = new PDF('P','mm','A4');
      
      $pdf->AliasNbPages();
      $pdf->AddPage();
      $pdf->SetAutoPageBreak(TRUE, 44);
      $pdf->SetXY(10,5);
       $pdf->SetFont('Arial','B',18);
      $pdf->Cell(45,30, utf8_decode('Informe Médicos Referidos: '),0,0,'L');
      $pdf->SetXY(10,15);
      $pdf->SetFont('Arial','B',12);
      $pdf->Cell(50,30, 'Periodo: del ' . $fi . ' al ' . $ff  ,0,1,'L');
      $pdf->SetXY(10,45);
      $pdf->SetFont('Arial','B',14);
      $pdf->Cell(20,10,'NUM',1,0,'L');
      $pdf->Cell(35,10,'PACIENTES',1,0,'L');
      $pdf->Cell(135,10,'MEDICO',1,1,'L');
      $pdf->SetFont('Arial','',12);
      $n=0;$L=0;while($row = mysqli_fetch_array($resultado)) { $l=$l+1;
      $n=$n+$row['num'];
      $pdf->Cell(20,10,$l,1,0,'L');
      $pdf->Cell(35,10,$row['num'],1,0,'L');
      $pdf->Cell(135,10,utf8_decode($row['ref_nombre']),1,1,'L');  
      
      }
      $pdf->SetFont('Arial','B',14);
      $pdf->Cell(20,10,'TOTAL',1,0,'L');
      $pdf->Cell(170,10,$n,1,1,'R');
     
      
       
   
       $pdf->Output();
   }     
   
   ?>