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 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号