I am trying to use an if condition within a variable containing html. I am getting errors with a standard condition and a ternary condition. Am I going about this the right way, or is there a different way I should be doing this?
Both methods I have tried:
$test = "
<tr>
<th><a href=\"installs.php?column=username&order=" . $asc_or_desc . "\">Username<i class=\"fas fa-sort" . if($column == 'username'){ '-' . $up_or_down; } else {''} . "\"></i></a></th>
</tr>
";
and tarnery:
$test = "
<tr>
<th><a href=\"installs.php?column=username&order=" . $asc_or_desc . "\">Username<i class=\"fas fa-sort" . $column == 'username' ? '-' . $up_or_down : '' . "\"></i></a></th>
</tr>
";
ifcannot be concatenated in PHP. The ternary operator's result can, but you probably should use brackets, as if to not have the concatenation precede the ternary operator.