dongyue0263 2012-01-16 00:01
浏览 35
已采纳

如何使用mysql数据库中的网站显示iframe?

Hi guys I'm trying to somewhat of an autosurfer and for the life of my I cannot figure out how to use iframes on my site to display all of the sites I have in my mysql database. Now all of the website urls are stored in a column in my table in the database, so I assume I'll need to assign them to an array. But my main problem is getting them to display each site for fifteen seconds then load a different one. I understand iframes for the most part, but I don't get how to get it to show a site, refresh show another, etc. I also can't figure out how to load the sites into an array for the iframe to use. Please help. Thanks.

  • 写回答

1条回答 默认 最新

  • doucan9079 2012-01-16 00:37
    关注

    You will need to use JavaScript to refresh your iframe.

    Let's say this is your iframe:

    <iframe id="iframe" src="http://www.google.com"></iframe>
    

    You'll need to use JavaScript to do the refresh, and AJAX if you want it to get data from your database. So do something like this in a javascript file (I'm using jQuery):

    $(function(){
        function refresh_iframe(){
            $.get('iframe_url.php', function(data){
                // set iframe src to the url that the php gave us
                $('#iframe').attr('src', data);
                // run this function again in 15s
                setTimeout("refresh_iframe()",15000);
            });
        }
        // run the first time
        refresh_iframe()
    });
    

    Then in iframe_url.php you'd have something like:

        <?php
                $q = mysql_query("SELECT `url` from `iframe_urls`");
                $results = mysql_fetch_assoc($q);
                $key = array_rand($results);
                echo($results[$key]['url']);
        ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 STM32无法向设备写入固件
  • ¥15 使用ESP8266连接阿里云出现问题
  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并