duanhu7400 2015-12-03 07:18
浏览 54
已采纳

根据当前系统时间自动生成输入值

I am creating a production recording system. What I want is that to automatically generate the input in "hour" based on the current system time. For example if the system time is in between 7.00 am and 7.15 am, the "hour" should be 1.Like that it should continue. I have written the following code but seems like it is wrong.Can anyone give me suggestions for that?

<?php
      $sql="SELECT CURTIME() AS Time";
      $result=mysqli_query($conn,$sql);
      while($row = mysqli_fetch_array($result)){
      $time=$row['Time'];

    }
    if("07:00:00"<="$time"<="07:15:00"){
  echo "<input class='form-control' type='text' name='hour' value='1' readonly >";

    }
       ?> 
  • 写回答

2条回答 默认 最新

  • donglv9813 2015-12-03 08:01
    关注

    It's probably easiest to manipulate times using timestamps. You can set the start and end times and then do a simple conditional to display the form element you want to display.

    $current_time = time();
    $start = strtotime("07:00:00");
    $end = strtotime("07:15:00");
    
    if ($current_time > $start && $current_time < $end)
    {
       echo "<input class='form-control' type='text' name='hour' value='1' readonly >";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改