dongsu3664 2015-11-06 13:08
浏览 69
已采纳

PHP倒计时和待办事项

I have a few questions. I need a countdown to 17:00 (5 PM) each day. After 17:00, i want to echo a message. Then, the timer needs to reset after 23.59. How can i do this with PHP?

My next question is about a To Do list. I have a functional ToDo list in PHP, but i want to be able to see how many tasks i have without needing to count them myself. Below is the code i have of the To Do list:

<?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></head>
<body>

<?php


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){


#REMOVE

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

}

Any help would be appreciated!

  • 写回答

1条回答 默认 最新

  • dspvin19712 2015-11-06 13:15
    关注

    For your 2nd question :

    You could define an index let's call it $i;

    So :

    $i = 0;
    

    Then increment it everytime the foreach is executed :

    foreach($_SESSION['todo'] as $id => $item){
    
    $i++;  
    
    echo "
        <form action='' method='post'>
        <input type ='hidden' name='remove_id' value='$id'>
        <input type='submit'  value='-'>
        $item
        </form>
        ";
    
    }
    

    Then echo $i; should give you your total of tasks.

    Also please put one question at a time en recreate another post with what you've tried for your first question.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛