我需要在mysql数据库的php文件中显示iframe的URL。
将URL存储在名为videourl的表中的mysql数据库和名为videourl的列中。
我可以从mysql数据库中获取URL并在php页面上回显它,但我不能将它用作n iframe scr!
这是我到目前为止所做的事情:
<?php
echo "<iframe src=\"{$videourl}\" style=\"background: #fff;\" frameborder=\"0\" height=\"450\" scrolling=\"auto\" width=\"100%\"></iframe>";
?>
但由于某种原因,这不起作用。并且它不起作用我的意思是它没有在PHP页面上显示任何内容!
这样做的最佳方式是什么?
由于
编辑:这是我的新闻代码,但仍无效:
<?php
$con=mysqli_connect("localhost","db_username","password","db_name");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM videourl");
while($row = mysqli_fetch_array($result))
{
echo "<td>" . $row['videourl'] . "</td>";
}
echo "<iframe src=\" . $videourl . \" style=\"background: #fff;\" frameborder=\"0\" height=\"450\" scrolling=\"auto\" width=\"100%\"></iframe>";
?>
最终编辑:
好的我已经完成了。
如果有兴趣的话,你应该怎么做:
while($row = mysqli_fetch_array($result))
{
$id = $row["id"];
$videourl = $row["videourl"];
$date_added = $row["date_added"];
}
echo "<iframe src=\"{$videourl}\" style=\"background: #fff;\" frameborder=\"0\" height=\"100%\" scrolling=\"auto\" width=\"100%\"></iframe>";
答案 0 :(得分:1)
你做错了是你忘了设置$videourl
的价值。
您在$row
中获取了一个rsult行。之后,您必须将$row["videourl"]
分配给$videourl
,否则$videourl
将为空,而您的iframe src
将为空。
答案 1 :(得分:0)
花括号怎么了?试试这个。
echo "<iframe src='$videourl' style='background: #fff;' frameborder='0' height='450' scrolling='auto' width='100'></iframe>";