dongzi0857
dongzi0857
2015-06-27 09:46
浏览 16
已采纳

使用<iframe>时,foreach循环仅返回一个值

Following is the PHP code I'm facing problem with:

<?php 
    $query="SELECT `url` FROM `videos";
    $query_run=mysql_query($query);
    while($row=mysql_fetch_array($query_run)){
        $result[]=$row;}
        foreach($result as $var){
            $url=$var['0'];
            echo "<iframe width='250' height='200' src='".$url."' frameborder='0'>";
        }
?>

The problem is that it returns only one result of <iframe> tag, but echoing out $url i.e

<?php 
    $query="SELECT `url` FROM `videos`";
    $query_run=mysql_query($query);
    while($row=mysql_fetch_array($query_run)){
        $result[]=$row;}
        foreach($result as $var){
            $url=$var['0'];
            echo $url;
        }
?>

returns all the available results.

Please help

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongtuo3370
    dongtuo3370 2015-06-27 10:08
    已采纳

    You have to specify a closing tag </iframe>.

    <?php 
        $query="SELECT `url` FROM `videos";
        $query_run=mysql_query($query);
        while($row=mysql_fetch_array($query_run)){
            $result[]=$row;}
            foreach($result as $var){
                $url=$var['0'];
                echo "<iframe width='250' height='200' src='".$url."' frameborder='0'></iframe>";
            }
    ?>
    
    点赞 评论

相关推荐