Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Refresh automaticlly when new results come in.

    I have a simple page that displays the content of a database but I need it to refresh automatically when new entries are submitted. I have tried searching for different tutorials, all of which either do not explain it well enough or it plain do not work, with comments to back it up. I would like to know your take on how to go about doing something like this.

    ~Thanks in advance

  • #2
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    What about a meta refresh every 30s or something like that?

    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #3
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I would really prefer a script that detects when the database is updated and refreshes the results page.

  • #4
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by muggin View Post
    I would really prefer a script that detects when the database is updated and refreshes the results page.
    You should consider using some AJAX-style for that.

    I'm using one to update players in my chat.

    You could for example make a JS timer that calls Testing() every second. What it does is do a GET request to somefile.php and displays the contents that is echo'ed from somefile.php in the div called myDiv. It doesn't have to be a PHP file tho.

    Code:
    function Testing()
    {   
        var getRequest;
            
        try
        {
            getRequest = new XMLHttpRequest();
        }
        catch (e)
        {
            try
            {
                getRequest = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e)
            {
                try
                {
                    getRequest = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch (e)
                {
                    alert("Broken!");
                    return false;
                }
            }
        }
        
        getRequest.onreadystatechange = function()
        {
            if (getRequest.readyState == 4) // 4 = complete
            {
                var ajaxDisplay = document.getElementById('myDiv');
                ajaxDisplay.innerHTML = getRequest.responseText;
            }
        }
    
        getRequest.open("GET", "somefile.php", true);
        getRequest.send(null);
        return true;
    }
    Then you could do..

    somefile.php
    Code:
    <?php
        // do database stuff here.. and echo it out.
        echo 'Some random number.. ' . rand(100, 200);
    ?>
    In your HTML file..
    Code:
    <div id="myDiv">
    Results will display here..
    </div>
    <br />
    <input id="Submit" type="submit" value="Click me" onclick="javascript:Testing()" />
    Something like that..
    Last edited by valvet; 12-17-2006 at 06:16 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •