suhas gawde suhas gawde - 1 month ago 10
MySQL Question

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.

Answer

The problem is with your URL value.Replace "watch?v=" in video url with "v/" and try again.For example I tried with

<iframe width="560" height="315" 
src="https://www.youtube.com//v/txSGdNONUJE" frameborder="0" allowfullscreen></iframe> 

The above code will work fine.

Comments