www.webdeveloper.com
Results 1 to 7 of 7

Thread: Display new record every 5 seconds

  1. #1
    Join Date
    Mar 2007
    Posts
    41

    Display new record every 5 seconds

    Hi to everybody,
    i've a page that display one product from a table (db access), i need to change the record displayed every 5 seconds without reboot the page.
    I'm thinking at javascript or flash, wich is the quicker and simpler way?
    Thank you very much.

  2. #2
    Join Date
    Mar 2006
    Posts
    591
    Javascript or flash can be done.
    Another way is to use Ajax for this.

  3. #3
    Join Date
    Mar 2007
    Posts
    41
    Any tutorial or guide for it?

  4. #4
    Join Date
    Jul 2008
    Location
    Athens, Greece
    Posts
    74

  5. #5
    Join Date
    Mar 2006
    Posts
    591
    On the web there are several good tutorials on starting with ajax.
    Try searchin on theme.
    I think I have some good code examples of ajax. But I have to look for them.

  6. #6
    Join Date
    Mar 2007
    Posts
    41
    thanks, i've already done something with ajax + php and ajax + cf , i'm looking for a tutorial if anybody knows, that explain my task.
    I just need a box in a page that refresh every 5 seconds taking every times a new record from the db.
    Hope somebody can help me.
    Bye,
    Giacomo

  7. #7
    Join Date
    Jul 2008
    Location
    Athens, Greece
    Posts
    74
    you will need to do something like
    HTML Code:
    <script type="text/javascript">
    var counter = 1;
    var timer=setTimeout("LoadNewRecord()",5000);
    
    function LoadNewRecord()
    {
     // Use ajax here to call another page which will take as parameter counter
    // and will return the appropriate record (as rendered html) from the database
    // something like
    Ajax.get("dbreader.php?counter=" + counter, callbackfunction_once_ajax_completes);
    counter++;
    timer=setTimeout("LoadNewRecord()",5000);
    }
    
    function callbackfunction_once_ajax_completes()
    {
     // get the response from the ajax
    // and display it in the html
    var contents = <the response from the ajax object>;
    var mydiv = document.getElementById("theIDofyourDIV");
    mydiv.innerHTML = contents;
    }
    </script>
    a bit primitive .. but it is to get an idea ..
    Last edited by gabriele; 07-04-2008 at 12:30 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles