Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: php time driven events??? need some help!!!

  1. #1
    Join Date
    Jun 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default php time driven events??? need some help!!!

    Basically I need to do an event every minute (60 seconds) and display the minutes on the page. So I need a looped function that displays the minute it is on and do a function every time as well.

    I understand I need to do a loop based on time (60 seconds) but dont know how!!! It also needs to stop once its done it for 45 minutes.

    can any one help?

    Need help big time, thank you.

  2. #2
    Join Date
    Dec 2005
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    not with php, javascript is the right language.
    Code:
    <script type="text/javascript">function clock() {
    d = new Date();
    h = d.getHours();
    min = d.getMinutes();
    document.getElementById('blah').innerHTML = h + ":" + min;
    setTimeout("clock()", 60000);
    }
    
    window.onload = clock;
    </script>
    <span id="blah"></span>

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Indeed. PHP operates server side and will only be executed when a page loads... there is no way for it to react to time, user input (like mouseover, clicking, pressing a key, etc.).

    (There is AJAX which uses javascript to go behind the scenes and grab a php page, but that is still based in javascript, and is very complex to learn, and you don't need it here.)
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. #4
    Join Date
    Jun 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default thank you, after a bit of research I got that answer too!

    thank you, after a bit of research I got that answer too! its a hard old language php at times, I do asp.net too and thats all in one!! php needs to be expanded! a php.net lol! Well javascript here I come! ready or not! lol thanks for the help.

  5. #5
    Join Date
    Jun 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation

    another question, if i place this on a php page, the page loads. It should display 0:01 then 0:02 ....... and so on till it hits 0:59 then shows 1:00, 1:01.

    On the 1:00 I want a function to perform and do this every minute for 45 minutes.

    I hope this is clear, if the page has to reload it has to reload but I would like just the function to perform over and over again.

    Cheers.

  6. #6
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    If you were using Flash I could make it work in a few seconds.. LOL

    Although it seems you are basically asking the same thing... you have one that executes every second...

    So can't you write another one using the same standards, that checks the first and when that is at 60 seconds execute the second?

    I am no JS guy... Hell, I am not much good at anything except Flash, and even that is ify.. LOL But it seems logical to me...
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  7. #7
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    You seem to have missed the point. PHP needs to reload, and reloading takes more than a second in many cases... it won't work. I tried a 1sec refresh rate on something one time and it displayed nothing because it was reloading before it got the info... weird.

    You'd want to use javascript here.

    It's pretty simple, but I don't know the exact code...

    1. Count time.
    2. Every 1000 microseconds, add 1 to the time.
    3. If (time==100) {time = 0; min++;}
    4. If (min==45)...end...or?

    Look up code for counting time; look up code for displaying on a page.

    That's it.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. #8
    Join Date
    Jul 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default One more similar question

    values of certain fields of a table in a database has to change at the start of every year(1st jan), is this possible in a MYSQL database or please tell me how to work around it, i am using JSP and javascripting... thanks in advance.

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Cron jobs are the best idea here.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    This is a really bad idea,but you can do it like this in PHP.
    PHP Code:
    <?php
    set_time_limit
    ('3000');
    function 
    callthis(){
    //function called once every minute
    }
    $i 1;
    while(
    $i <= 45){
    sleep('60');//change this to 1 for testing,that's what I did
    callthis();
    echo 
    $i." minutes\n";
    flush();
    $i++;
    }
    ?>

Bookmarks

Posting Permissions

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