doumou1864 2015-11-08 12:09
浏览 60
已采纳

重置的PHP倒计时

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条回答 默认 最新

  • doukuiqian5345 2015-11-08 12:17
    关注

    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.";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)