Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8875887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:05:44+00:00 2026-06-14T19:05:44+00:00

I’m trying to generate a pdf using the FPDF class but the problem I’m

  • 0

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.

Here are the codes in the script meant to generate the pdf

        <?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->getPubCourseDetails($_GET['c_id']);
        }




        class PDF extends FPDF
        {   


    public $course_details;

    public function setData($input){
        $this->course_details = $input;
    }


        function Header()
        {
            // Logo
            $this->Image('s_pdf_logo.png',10,6,30);
            // Arial bold 15
            $this->SetFont('Arial','B',20);
            // Move to the right
            $this->Cell(40);    
            // Title
            $this->Cell(30,10,$this->course_details['comp_name']);
            // Draw an header line
            $this->Line(10,26,200,26);
            // Line break
            $this->Ln(20);
        }

        function Footer()
        {
            // Position at 1.5 cm from bottom
            $this->SetY(-15);

            // Begin with regular font
            $this->SetFont('Arial','',9);
            // Then put a blue underlined link
            //$this->SetTextColor(0,0,255);
            $this->SetFont('','U');
            $this->Write(10,$this->course_details['comp_name'],'http://www.skills.com');
            // Arial italic 8
            $this->SetFont('Arial','I',9);
            // Page number
            $this->Cell(0,10,'Page '.$this->PageNo().' ',0,0,'R');
        }


        function BodyTop()
        {
        // Course title cell
        $this->Cell('',10,'',0,0,'C');
        $this->Ln();

        /* Build cells for the first row */

        $this->SetFont('Arial','',10);
        $this->SetY(40);

        // First Row
        $this->Cell(35,8,'Starting Date : ',0,0,'L');
        $this->Cell(30,8,$this->course_details['event_date'],0,0,'C');
        $this->SetX(150);
        $this->Cell(25,8,'Course Fee : ',0,0,'L');
        $this->Cell(20,8,$this->course_details['fee'],0,0,'C');
        $this->Ln();

        // Second Row
        $this->Cell(35,8,'Seating Capacity : ',0,0,'L');
        $this->Cell(30,8,$this->course_details['sit_capacity'],0,0,'L');
        $this->SetX(150);
        $this->Cell(25,8,'Duration : ',0,0,'L');
        $this->Cell(20,8,$this->course_details['duration'].' Day(s)',0,0,'L');
        $this->Ln();

        // Third Row
        $this->Cell(35,8,'Venue : ',0,0,'L');
        $this->Cell(30,8,$this->course_details['venue'],0,0,'L');
        $this->SetX(150);
        $this->Cell(25,8,'City : ',0,0,'L');
        $this->Cell(20,8,$this->course_details['city'],0,0,'L');
        $this->Ln();

        // Fourth Row
        $this->Cell(35,8,'Other Details : ',0,0,'L');
        $this->Cell(150,8,$this->course_details['other_det'],0,0,'L');
        $this->Ln();


        }


        function CourseBody()
        {

        $this->SetY(80);

        //$this->WriteHTML($html);
        $this->Write(10,$this->course_details['desc']);

        }

        function PrintChapter()
        {
            $this->AddPage();
            $this->BodyTop();
            $this->CourseBody();
        }
        }

        $pdf = new PDF();

$pdf->setData($course_details);
        //$pdf->Header();

        $pdf->SetAuthor($this->course_details['comp_name']);
        $pdf->PrintChapter();
        $pdf->Output();



        ?>

I hope to get some help with this…Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:05:45+00:00Added an answer on June 14, 2026 at 7:05 pm

    It’s just basic OOP (object oriented programming) really.

    Add a variable to your PDF Class as such:

    public $data;
    

    Add a function within your PDF Class which accepts a parameter and use this function to set the variable above:

    public function setData($input){
        $this->data = $input;
    }
    

    And then you’ll be able to access $this->data from within your PDF Class. Don’t forget to actually call the function that you just defined (just after the constructor).

    EDIT:
    To set the data:

    $pdf = new PDF();
    $pdf->setData($course_details);
    

    Then within your PDF class $this->data will be your array. You might want to do the following so you can understand the format of your array:

    print_r($this->data);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.