$pollPart .= '
<tr>
<td valign="top" nowrap="nowrap">'.$question['question'].'</td>
<td valign="top" height="10" width="100%" style="padding: 0px 10px;">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td valign="top" width="'.$percentage.'%" '.if($percentage > 0){$pollPart .= 'style="background: url(\'/includes/poll/images/bar.jpg\') repeat-x;"';}.'><img src="/includes/poll/images/dot.gif" width="1" height="19" /></td>
<td valign="top" width="'.$percentage2.'%"></td>
</tr>
</table>
</td>
<td valign="top">'.$responses['total'].'</td>
</tr>
';
I am getting the Syntax on the following line:
<td valign="top" width="'.$percentage.'%" '.if($percentage > 0){$pollPart .= 'style="background: url(\'/includes/poll/images/bar.jpg\') repeat-x;"';}.'><img src="/includes/poll/images/dot.gif" width="1" height="19" /></td>
Specifically this part:
if($percentage > 0){$pollPart .= 'style="background: url(\'/includes/poll/images/bar.jpg\') repeat-x;"';}
Any input on this would be greatly appreciated, Thank You!
You can’t do if-blocks inside of a concatenation of strings. If you want to do an inline ternary if/else, the syntax is a little different.
Instead of
You would structure it like
CONDITION ? TRUE-PART : FALSE-PART:I use an empty string (
'') since no false condition is needed, but something needs to be returned in order to complete the statement and to concatenate with the rest of the string.Alternatively, you can end your string of concatenations, place the if block after it, then start again with
$pollPart .=.