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 3 of 3

Thread: Times Problem

  1. #1
    New to the CF scene
    Join Date
    Mar 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Times Problem

    So i want to select information from database and after 20 second when file has opened write another information in that row.

    i wrote such code:
    PHP Code:
    <?php
    $select 
    mysql_query("SELECT * FROM news WHERE id=5");
    $time time();
    $insert mysql_query("INSERT INTO news SET last_time = '$time'");
    //
    // HERE IS HTML TAGS
    //
    $time2 time() + 20;
    $last_time mysql_query("SELECT last_time FROM news WHERE id = 5 ");
    if(
    $time2 $last_time){
    $addshows mysql_query("INSERT INTO news SET shows = 2");
    }
    ?>
    but it is not working how i can to work this script? or is another way to make such script?

  • #2
    New Coder
    Join Date
    Dec 2005
    Posts
    35
    Thanks
    1
    Thanked 1 Time in 1 Post
    Because PHP is server side as far as im aware this is not possible, the server reads the php and then executes it. There is not wait command, therefore the best way to do this would be with HTML.

    If you google HTML refresh it should come up with something. I cant remember the exact code and I cant get to it here. Post back if you can or cannot find it and if not I will post it when I get home.

  • #3
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Well, you could use flush(); to send the output and sleep(20); to wait, but PHP is not the best way to do this because you'll either hit the loading time limit or you'll have to circumvent it, and that will cause more problems than solutions. If the information is static you can load it into Javascript vars and then use it to display them every 20 seconds.


  •  

    Posting Permissions

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