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

报告相同问题?

悬赏问题

  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误