Timer(s) - Do you think this should work

Discussion in 'PHP' started by oo7ml, Jan 9, 2012.

  1. #1
    Hi, my site allows users (buyers) to buy e-learning courses for other users (receivers). In order to complete a course, the receiver must complete the same task every single day for duration of the course (1 week)

    When a user starts the first task, the time is recorded and the receiver must complete the task each day before that hour ($first_hour) each day (i.e: on day 1, if the receiver starts the first task of the mission at 15:45pm then the receiver will have to complete the rest of the tasks for that mission before 15:00pm each day. The receiver can only complete one task per day.

    A receiver can have many different courses assigned to their account, so when the receiver logs into their account, they will be re-directed to the my-account.php page where they will see a count down timer.

    The timer will display one of two things:

    1 (priority) - get the closest incomplete mission where the $first_hour is greater than the current time (where current time HAS NOT passed $first_hour) and display count down timer for "TIME LEFT TO COMPLETE NEXT TASK"

    IF THERE ARE NO INCOMPLETE MISSIONS

    2 - get the closest complete mission where the $first_hour is less than the current time (where current time HAS passed $first_hour) and display the timer for "TIME LEFT BEFORE YOU CAN START NEXT TASK"

    Here is my pseudo code:

    ==========

    SELECT * (or whatever is needed) FROM missions WHERE $mission_status = live AND $receiver_id = user_session

    IF result = 0, then change timer counter to display "no live missions"

    ELSE

    SELECT * (or whatever is needed) FROM missions WHERE $today_status = incomplete AND $first_hour is > than current_time ORD $first_hour DESC, LIMIT 1

    IF result is not 0

    01 - display the counter for "TIME LEFT TO COMPLETE NEXT TASK"

    ELSE if result is 0

    SELECT * (or whatever is needed) FROM missions WHERE $today_status = complete AND $first_hour is < than current_time ORD $first_hour DESC, LIMIT 1

    01 - display the counter for "TIME LEFT BEFORE YOU CAN START NEXT TASK"

    ==========

    My code is only pseudo code and i know if it all over the place but i just want to know if you think it is on the right path, thanks in advance...
     
    oo7ml, Jan 9, 2012 IP
  2. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #2
    yes. this should work, the idea is robust and probably there are some work around in your queries that is relevant to your database design. nevertheless its fine.
     
    bartolay13, Jan 11, 2012 IP
  3. oo7ml

    oo7ml Well-Known Member

    Messages:
    656
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #3
    Cool... thanks for your help, much appreciated...
     
    oo7ml, Jan 11, 2012 IP