Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying youtube video from mysql database using php?

I want to display youtube video on a page, the following is my code in order to fetch youtube video URL from the database stored in mysql and then display it by iterating using while loop. However, the iframe does not display any video inside it.

<?php
   if ($get_result != false) {
       while ($row = mysqli_fetch_array($get_result, MYSQLI_ASSOC)) {
?>
          <iframe width="560" height="315" src="<?php echo $row["url"]; ?>" frameborder="0" allowfullscreen></iframe>
<?php
       }
   }
?>

I have also tried using video tag inside while loop but it does not display the Youtube video inside the video player. Please help me to solve this issue.

like image 481
suhas gawde Avatar asked Dec 03 '25 01:12

suhas gawde


1 Answers

You can use Youtube with embed, like this:

<iframe width="560" height="315" src="https://www.youtube.com/embed/<?php echo $row["url"]; ?>?autoplay=1&autohide=1&controls=1&showinfo=0&modestbranding=1&rel=0"></iframe>
like image 62
skeptic Avatar answered Dec 04 '25 14:12

skeptic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!