title: how to pass variable data from an array into fpdf in php
body: <p>I'm trying to generate a pdf using the FPDF class but the problem I'm having is how to pass variable data fetched from mysql database (queried data are stored in an array) into the pdf generated.</p>
  
  <p>Here are the codes in the script meant to generate the pdf</p>
  
  <pre><code>        &lt;?php
          @include_once("includes/db.php");
          require('fpdf/fpdf.php');
          @include_once("includes/course_info_query.php");
  
          $obj = new trainingCourses();
          $course_details = array();
          if(isset($_GET['c_id'])){
                  $course_details = $obj-&gt;getPubCourseDetails($_GET['c_id']);
          }
  
  
  
  
          class PDF extends FPDF
          {   
  
  
      public $course_details;
  
      public function setData($input){
          $this-&gt;course_details = $input;
      }
  
  
          function Header()
          {
              // Logo
              $this-&gt;Image('s_pdf_logo.png',10,6,30);
              // Arial bold 15
              $this-&gt;SetFont('Arial','B',20);
              // Move to the right
              $this-&gt;Cell(40);    
              // Title
              $this-&gt;Cell(30,10,$this-&gt;course_details['comp_name']);
              // Draw an header line
              $this-&gt;Line(10,26,200,26);
              // Line break
              $this-&gt;Ln(20);
          }
  
          function Footer()
          {
              // Position at 1.5 cm from bottom
              $this-&gt;SetY(-15);
  
              // Begin with regular font
              $this-&gt;SetFont('Arial','',9);
              // Then put a blue underlined link
              //$this-&gt;SetTextColor(0,0,255);
              $this-&gt;SetFont('','U');
              $this-&gt;Write(10,$this-&gt;course_details['comp_name'],'http://www.skills.com');
              // Arial italic 8
              $this-&gt;SetFont('Arial','I',9);
              // Page number
              $this-&gt;Cell(0,10,'Page '.$this-&gt;PageNo().' ',0,0,'R');
          }
  
  
          function BodyTop()
          {
          // Course title cell
          $this-&gt;Cell('',10,'',0,0,'C');
          $this-&gt;Ln();
  
          /* Build cells for the first row */
  
          $this-&gt;SetFont('Arial','',10);
          $this-&gt;SetY(40);
  
          // First Row
          $this-&gt;Cell(35,8,'Starting Date : ',0,0,'L');
          $this-&gt;Cell(30,8,$this-&gt;course_details['event_date'],0,0,'C');
          $this-&gt;SetX(150);
          $this-&gt;Cell(25,8,'Course Fee : ',0,0,'L');
          $this-&gt;Cell(20,8,$this-&gt;course_details['fee'],0,0,'C');
          $this-&gt;Ln();
  
          // Second Row
          $this-&gt;Cell(35,8,'Seating Capacity : ',0,0,'L');
          $this-&gt;Cell(30,8,$this-&gt;course_details['sit_capacity'],0,0,'L');
          $this-&gt;SetX(150);
          $this-&gt;Cell(25,8,'Duration : ',0,0,'L');
          $this-&gt;Cell(20,8,$this-&gt;course_details['duration'].' Day(s)',0,0,'L');
          $this-&gt;Ln();
  
          // Third Row
          $this-&gt;Cell(35,8,'Venue : ',0,0,'L');
          $this-&gt;Cell(30,8,$this-&gt;course_details['venue'],0,0,'L');
          $this-&gt;SetX(150);
          $this-&gt;Cell(25,8,'City : ',0,0,'L');
          $this-&gt;Cell(20,8,$this-&gt;course_details['city'],0,0,'L');
          $this-&gt;Ln();
  
          // Fourth Row
          $this-&gt;Cell(35,8,'Other Details : ',0,0,'L');
          $this-&gt;Cell(150,8,$this-&gt;course_details['other_det'],0,0,'L');
          $this-&gt;Ln();
  
  
          }
  
  
          function CourseBody()
          {
  
          $this-&gt;SetY(80);
  
          //$this-&gt;WriteHTML($html);
          $this-&gt;Write(10,$this-&gt;course_details['desc']);
  
          }
  
          function PrintChapter()
          {
              $this-&gt;AddPage();
              $this-&gt;BodyTop();
              $this-&gt;CourseBody();
          }
          }
  
          $pdf = new PDF();
  
  $pdf-&gt;setData($course_details);
          //$pdf-&gt;Header();
  
          $pdf-&gt;SetAuthor($this-&gt;course_details['comp_name']);
          $pdf-&gt;PrintChapter();
          $pdf-&gt;Output();
  
  
  
          ?&gt;
  </code></pre>
  
  <p>I hope to get some help with this...Thanks</p>