Welcome Guest, Not a member yet? Register   Sign In
Insert Values from DB into PDF form using TCPDF
#1

[eluser]Unknown[/eluser]
Hello All,

I am using TCPDF library to generate PDF. I have successfully used TCPDF using procedural PHP. However, I was developing same application using CI and TCPDF.

Here is Controller
Code:
function index()
    {
$this->load->library('pdf');

        $this->pdf->AddPage();
        $this->load->model('create_pdf_model');
        $pdf_data = $this->create_pdf_model->get_details();

        
$tbl = <<<EOD
        
<table cellspacing="0" cellpadding="1" border="1">
    <tr>
        <td rowspan="3">$pdf_data</td>
        <td>Test</td>

    </tr>
  
</table>
EOD;

$this->pdf->writeHTML($tbl, true, false, false, false);
$y = $this->pdf->Output('test', 'I');  
$this->pdf->header("Content-type:application/pdf");
echo $y;

============== Model ============
Code:
$this->db->select('table');
        $this->db->from('employee');
        $this->db->where('emp_id', $this->uri->segment(3));
        $query = $this->db->get();
        $result = $query->result_array();
        return $result;
==========
I am not sure what going wrong. When I load the page it shows me PDF with value as "Array" in table not employee id.
I am trying to achieve is to get few values from table in DB and send it PDF (Id, Name, Address).

It would be great if any one can please guide me through this problem.

Thanks
#2

[eluser]darrentaytay[/eluser]
It's showing "Array" because your are trying to output an array. Try replacing

Code:
<td rowspan="3">$pdf_data</td>

with

Code:
<td rowspan="3">$pdf_data['emp_id']</td>

And see how that goes.
#3

[eluser]Unknown[/eluser]
Yes I treid that as well but it gives blank on output.

However, I figure that out now. I was missing this part
Code:
$pdf_data = $this->create_pdf_model->get_details();
        foreach ($pdf_data as $rows){
            $id = $rows->employee_id;
            $fname = $rows->first_name;
        }
Later in file
Code:
$tbl = <<<EOD
<table>
    <tr>
        <td rowspan="3">$id</td>
        <td>$fname</td>

    </tr>
  
</table>
EOD;

Now it works as excepted.

Thanks for your prompt response...Smile
#4

[eluser]the_unforgiven[/eluser]
Tried what you said pviral but getting this error

Parse error: syntax error, unexpected $end in /Applications/MAMP/htdocs/ksd/application/controllers/admin.php on line 427

and this is because of the syntax used for <<<EOD it doesn;t work or the foreach loop is incoorect too, can you help me?
#5

[eluser]the_unforgiven[/eluser]
Anyone got any advice on this please?
#6

[eluser]the_unforgiven[/eluser]
anyone?




Theme © iAndrew 2016 - Forum software by © MyBB