3

I have a coding matter i need your aid with. I have attempted to solve it for a few days, but all it results in is frustration. I haven't found any existing examples or help on the internet, and all i have done so far is staring at my code, my mind blank.

I need a countdown to 17:00 (5 PM) each day, echoing a message saying that a certain amount of time is remaining until 17:00. After 17:00, i want to echo another message. Then, the timer needs to reset after 23.59. How can i do this with PHP?

Any help would be appreciated! Below is the code i already have, but i don't think any part of it would affect what i need help with:

<?php
    session_start();

    #ADD ITEM
    if( isset( $_POST['newitem'] ) ){
        $_SESSION['todo'][]=$_POST['newitem'];
    }


    #REMOVE ITEM
    if( isset( $_POST['remove_id'] ) ){
        $id = $_POST['remove_id'];
        unset( $_SESSION['todo'][$id] );
    }
?>
<html>
    <head>
        <title></title>
    </head>
    <body>
<?php
    $i = 0;

    echo "<h1>To Do</h1>";

    #SUBMIT
    echo "
    <form action='' method='post'>
        <input type='text' name='newitem'>
        <input type='submit'>
    </form>
    ";


    foreach( $_SESSION['todo'] as $id => $item ){
        $i++; 

        #REMOVE
        echo "
            <form action='' method='post'>
                <input type ='hidden' name='remove_id' value='$id'>
                <input type='submit'  value='-'>
                $item
            </form>";
    }

    echo $i;

    #CHANGE BACKGROUND COLOR DEPENDING ON DAY
    $day=date("l");

    switch($day) {
        case 'Monday':
            $bg_color = "red";
            break;
        case 'Tuesday':
            $bg_color = "blue";
            break;
        case 'Wednesday':
            $bg_color = "purple";
            break;
        case 'Thursday':
            $bg_color = "gray";
            break;
        case 'Friday':
            $bg_color = "yellow";
            break;
        case 'Saturday':
            $bg_color = "green";
            break;
        case 'Sunday':
        default:
            $bg_color = "beige";
            break;
    }

    echo "<body style='background-color:$bg_color'>";
?>
    </body>
</html>
1
  • In your code you have declared the html structure ( thogh I did add the closing pieces so that the example is valid ) but towards the bottom you echo the body tag again with a style..... Commented Nov 8, 2015 at 12:17

1 Answer 1

3

I need a countdown to 17:00 (5 PM) each day, echoing a message saying that a certain amount of time is remaining until 17:00. After 17:00, i want to echo another message. Then, the timer needs to reset after 23.59. How can i do this with PHP?

if(date("H") < "17") echo "There are " . (16 - date("H")) . " hours and " . (60 - date("i")) . " minutes left until 17:00.";
else if(date("H") == "17" && date("i") == "00") echo "It is 17:00.";
else echo "17:00 is over for today.";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.