1

The IF condition inside echo statement does not work.

I get this error:

Syntax error, unexpected ')' in

    echo ' <div class="panel-body">
         '.$dec.'
         '.(($ttype == "video")
             ? '<iframe class="embed-responsive-item" 
                width="560" height="315"
                src="https://www.youtube.com/embed/'.$only_id[1].'" frameborder="0"
                allowfullscreen=""></iframe>').'
                </div>';
trincot
  • 317,000
  • 35
  • 244
  • 286
cipher
  • 51
  • 7

2 Answers2

1

You can concatenate with variable. This will help you to avoid confusions

$html = '';
$html .= '<div class="panel-body">';
$html .= $dec;
$html .= ($ttype == "video")?'<iframe class="embed-responsive-item" width="560" height="315" src="https://www.youtube.com/embed/'.$only_id[1].'" frameborder="0" allowfullscreen=""></iframe>':'<!-- else part -->';
$html .= '</div>';
echo $html;
Sundar
  • 4,580
  • 6
  • 35
  • 61
1

Make your life easy and use like that:

<div class="panel-body">
<?php echo $dec; ?>
<?php
(($ttype == "video") ? '<iframe class="embed-responsive-item" width="560" height="315"
 src="https://www.youtube.com/embed/'.$only_id[1].'" frameborder="0"  allowfullscreen=""></iframe>' : '');
?>
</div>

In your code, you are missing the else condition of Ternary operator.

Solution with your code:

echo ' 
    <div class="panel-body">'.$dec.'
    '.(($ttype == "video") ? '
        <iframe class="embed-responsive-item" width="560" height="315" 
        src="https://www.youtube.com/embed/'.$only_id[1].'" frameborder="0" allowfullscreen="">
        </iframe>' : '').
    '</div>';
devpro
  • 16,184
  • 3
  • 27
  • 38