2017.8.22学习日志——php添加datepicker并对比大小

2017.8.22学习日志

继昨天学习怎么阅读和调试PHP代码之后,今天的效率快了很多,很多改动知道从哪地方下手。
那么今天的任务是按时间搜索每个人的工单情况,如愿以偿解决了问题。

首先我在需要添加功能的页面添加两个datepicker:

<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
    $( function() {
        $( "#datepicker1" ).datepicker();
    } );
    $( function() {
        $( "#datepicker2" ).datepicker();
    } );
</script>
<form action="" method="get">
  <div align="center">起止时间:<input type="text" id="datepicker1" name="datepicker1">
      至 <input type="text" id="datepicker2" name="datepicker2">
      <input type="submit" value="开始">
  </div>
</form>

我把datepicker的数据传递到本页面让PHP处理,值得一提的是,我是用的phpstorm开发工具,当我把提交方式设为”post”的时候,php接收良好,可以处理,可是以”get”方式传递则无法接收,调试echo打印 REQUEST使phpurlexplodeurldecodekv"get""post" _POST即可。

<?php
   $string= $_SERVER['QUERY_STRING'];
   $strarr = explode("&",$string);
    foreach($strarr as $id=>$arr) {
        $r=explode("=",$arr);
        $_GET[$r[0]]=urldecode($r[1]);
    }

    $datepicker1 = $_GET['datepicker1'];
    echo $datepicker1;
    $datepicker2 = $_GET['datepicker2'];
    echo $datepicker2;
//或者直接用post传递参数也可,不知道为什么get不能传数据。
?>

取得参数后,与已有的开始时间和完成时间对比,当开始和完成都在 datepicker1 datepicker2之间时,才显示出来,即我需要的按时间搜索功能。

<?php

  foreach($tasks as $task):
      $d1 = date("y-m-d",strtotime($task->finishedDate));

      if(strtotime($task->realStarted)>=strtotime($datepicker1)&&strtotime($d1)<=strtotime($datepicker2)&&strtotime($d1)>=strtotime($datepicker1)&&strtotime($d1)<=strtotime($datepicker2)||strtotime($datepicker1)==0||strtotime($datepicker2)==0){
      ?>
  <tr class='text-center'>
    <td><?php echo html::a($this->createLink('task', 'view', "taskID=$task->id"), sprintf('%03d', $task->id));?></td>
    <td><span class='<?php echo 'pri' . zget($lang->task->priList, $task->pri, $task->pri);?>'><?php echo $task->pri == '0' ? '' : zget($lang->task->priList, $task->pri, $task->pri)?></span></td>
    <td class='nobr'><?php echo html::a($this->createLink('project', 'browse', "projectid=$task->projectID"), $task->projectName);?></td>
    <td class='nobr'><?php echo html::a($this->createLink('task', 'view', "taskID=$task->id"), $task->name);?></td>
    <td><?php echo $task->estimate;?></td>
    <td><?php echo $task->consumed;?></td>
    <td><?php echo $task->estimate-$task->consumed;?></td>
    <td><?php echo $task->realStarted;?></td>
    <td class=<?php if(isset($task->delay)) echo 'delayed';?>><?php if(substr($task->deadline, 0, 4) > 0) echo $task->deadline;?></td>
    <td><?php echo $task->finishedDate;?></td>
    <td class='<?php echo $task->status;?>'><?php echo $lang->task->statusList[$task->status];?></td>
  </tr>
  <?php $countestimate += $task->estimate;
        $countconsumed += $task->consumed;
        $countleft += $task->estimate-$task->consumed;
        ++$counttask;}
  endforeach;?>

重点是时间对比大小,需要使用到php中的strtotime方法,把日期转换成时间戳形式,1502441119这种来对比大小,通过 d1=date("ymd",strtotime( task->finishedDate))方法去除后面的时分秒。

以上是今天的总结。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值