1

Below is my html code to display an exercise video from a database:

<video id = "video" width="640" height="360" controls = "controls" src="admin/exercise_content/<?php echo $data['exercise_video']?>" alt="Exercise" type="video/mp4"> Your browser does not support the video tag. </video>

Sometimes there won't be a exercise video in the database therefore I want to hide this tag. The video sample/container below is displayed if there is no video in the database. Is there any way to hide this video container when there's no video to be displayed?

default video displayed if exercise video empty in database

Thanks for any help!

Davidaj
  • 235
  • 3
  • 14

3 Answers3

2

Use this:

<? if ( trim($data['exercise_video']) != '' ) : ?>
<video id = "video" width="640" height="360" controls = "controls" src="admin/exercise_content/<?php echo $data['exercise_video']?>" alt="Exercise" type="video/mp4"> Your browser does not support the video tag. </video>
<? endif; ?>

This prints the video tag only when $data['exercise_video'] is not empty.

Hope this helps.

  • 2
    Better to use !empty($data['exercise_video']) as your code will throw a notice if it isn't set – George Aug 27 '15 at 19:54
2

try this

<?php if ( $data['exercise_video'] != '' ) { ?>
<video id = "video" width="640" height="360" controls = "controls"src="admin/exercise_content/<?php echo $data['exercise_video']?>" alt="Exercise" type="video/mp4"> Your browser does not support the video tag.       </video>
<?php }  ?>
Sahil Manchal
  • 472
  • 6
  • 20
1

Well using

<?php if (!empty($data['exercise_video']): ?>
<video id = "video" width="640" height="360" controls = "controls" src="admin/exercise_content/<?php echo $data['exercise_video']?>" alt="Exercise" type="video/mp4"> Your browser does not support the video tag. </video>
<?php endif ;?>

Would be much better.. Try it.. :)

Dev5G
  • 82
  • 7