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>'; 
4
  • you should add another value if it fails the condition </iframe>':"") Commented Feb 11, 2016 at 6:22
  • try this: 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>'; Commented Feb 11, 2016 at 6:22
  • try this:- 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>'; Commented Feb 11, 2016 at 6:23
  • If yur problem is solve than chose the best answer and mark as accepted Commented Feb 11, 2016 at 21:01

2 Answers 2

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; 
Sign up to request clarification or add additional context in comments.

Comments

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>'; 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.