jeudi 21 juillet 2016

How to change a php variable every 3 seconds?

<?php
        $sites = array('http://site1.net', 'http://site2.fr');
        ?>


        <script>


            function loadwebsite() {
                <?php
                    foreach ($sites as $site) {
                        $disp = echo $site;
                    }

                ?>
            }
            setInterval(loadwebsite, 3000);
        </script>

I want that my page displays the url of a website, changing every 3 seconds, like an auto surf.... For example the first 3 seconds, it displays http://site1.net ... and for 3 seconds, after 3 seconds, it displays http://site2.fr and alternatively... But I don't succeed to do that...

EDIT: I do it in javascript

<script>

        var sites = ['http://site1.net','http://site2.fr'];

        function loadwebsite(site) {
            document.getElementById("site").innerHTML = site;

        }
        for (var i=0;i<=1;i++) {
            site = sites[i];
            setInterval(loadwebsite, 3000, site);
        }

    </script>

I want to display one website from my array, changing every 3 seconds but I don't succeed to do that. How to do that ?

Aucun commentaire:

Enregistrer un commentaire