(Ask) How To Tcpdf Parsing Variable In Database?

Dear All,

Says, we want to create pdf use TCPDF. But, the data that we want to create is coming from database table.

We can set like Author Name setting, Paper Size, Margin, etc, and results to normal.

But when we want to echo the data from database, the result is the variabel do not want to convert to its value. We can get the pdf created here with the data from database, but the variable keep stick to its variable name, such as $FirstName, $LastName.

The original idea is, we want data must coming from database, because we can easily edit via browser. But the problem is the variables from database do not want to convert its value.

  1. How can we get true pdf result, where variables can convert its values? Right now I can not get its values, just its variables names.

Example of present values in database:

Halo, my name is $model->FirstName. I am $model->Age years old. My social number is $model->SocialNumber.

In TCPDF, results just like above, the variable not change at all. It is should:

Halo, my name is James. I am 45 years old. My social number is 123456789.

Thank you for your help.

Read PHP documentation, chapter ‘variable interpolation’

If I understand your problem correctly, consider the following:


    $date = '24 Jan 2014';

    echo "Today is $date";

    // output = Today is 24 Jan 2014

    echo 'Today is $date';

    // output = Today is $date

The difference is the quotation marks used.

If double quotes are used, php will process the variable within the string.

If single quotes are used, the string is considered a literal string and the variable will not be processed.