0

I am trying to use iFrame to dispaly some random videos. The links are stored in a database so i am using a loop to get them and use them as source for iFrame. When i just print out the url's it works fine they all appear, but when I try to add them as src for iFrame it wont appear. I get an empty box.

$loop = mysql_query("SELECT * FROM video") or die (mysql_error());
while ($row = mysql_fetch_array($loop)) {
    $tmp = $row['videos'];
    //echo $tmp;
?>
    <iframe width="420" height="315" src="<?php echo $tmp; ?>" ></iframe>
<?php   
}
?>
Manam
  • 1

1 Answers1

-1

Make sure $tmp starts with http://.

$loop = mysql_query("SELECT * FROM video") or die (mysql_error());
while ($row = mysql_fetch_array($loop)) {
    $tmp = $row['videos'];
    $tmp = strpos($tmp, "http://") ? $tmp : "http://" . $tmp;
    //echo $tmp;
?>
    <iframe width="420" height="315" src="<?php echo $tmp; ?>" ></iframe>
<?php   
}
?>
Christian Lundahl
  • 2,000
  • 3
  • 18
  • 29
  • My bad, the links are already starting with html: https: //www.youtube.com/watch?v=Y0hKpdnuXnw But it does not work either way – Manam Mar 20 '15 at 11:53
  • As mentioned in http://stackoverflow.com/questions/8698742/getting-youtube-com-to-load-in-iframe YouTube cannot be embedded other than links that starts with http://www.youtube.com/embed/ I actually had no idea about that before I posted my answer. – Christian Lundahl Mar 20 '15 at 12:21
  • Ohh now I see. It actually works when I use an embedded link :D – Manam Mar 20 '15 at 12:34