If / Else before TCPDF creation of HTML

if (isset($Name2))  {
	

$decdata =  "Something: $Something1 ";} 

else  {

$decdata =	"Something: $Something2";} 
  
// add a page
$this->AddPage();

When generating PDF it always use the first $decdata if Name2 is defined and Name1 is not defined but if I do like

if ($Name)  {

$decdata =  "Something: $Something1 ";} 

else  {

$decdata =	"Something: $Something2";} 
  
// add a page
$this->AddPage();

It always use det second $decdata even if $name is defined and name2 is not.

Any suggest what the problem might be?

I tried something so “dumb” as just having it done like this in fron of the TCPDF making and this seems working. So I dont know if this is TCPDF that prefers it this way or something I should have done different.

if (isset($Name2)) $decdata = "Something: $Something1 ";
if ($Name2) $decdata = "Something: $Something2 ";

Well what is the value of $NAME/$NAME2?

When you check it like so:

if($NAME){
    //do whatever
}

I believe it is treating the conditional check like/as a boolean value

I am confused on your examples. You show two different ones and your text is hard to understand.
It appears you want to use the first example. The second does not do what you want. But, the logic
must be sorted out. You need to create a test page with just the first example and see what happens.
Something like this:

<?PHP
$Name2 = "a test value";
if (isset($Name2))  {
	$decdata =  "Something1 ";
} else  {
        $decdata = "Something2 ";
} 
echo $decdata;
?>

This should always show Something1, not 2 ! Now if you do not set the value, it should always show
Something2. Therefore, I will guess you have invalid input for your code for $Name2. Have you attempted to debug your code? If so, how? One way would be to just kill the code at the point where
you compare $Name2 like die($Name2); and see what the value of it is. I am guessing that your code
is not setting the $Name2 value and that is why the second Something2 is setting.

Sponsor our Newsletter | Privacy Policy | Terms of Service