dongshuobei1037 2019-01-18 10:56
浏览 67
已采纳

PHP上的空字段处理

I have a table named hr events where, in one field, it outputs when a certain employee went on maternity leave;

On the return_date field, it displays the date when the employee got back from the maternity leave.

If the employee has not come back yet, we set a default value, as seen on CREATE statement below: CREATE (return_date DATE NOT NULL DEFAULT '0000-00-00',);

There is one last field on this report where it is supposed to show the employee's final return date to her activities: (c.return_date ,'%d/%m/%Y') AS c_return_date. As an SQL beginner, i'm struggling with this: whenever we have a (default 0000-00-00) value, c.return_date brings some sort of aleatory date, like: e.g 12/01/1999 , tho' it's a NULL field.

I've been trying to treat this with ISNULL(c.return_date, '') or ISNULL(c.return_date, 0) but it just doesn't work. In the above scenario, this last field should be blank or anything but this '12/01/1999'.

As for PHP, and that's why I'm editing this topic, I think there could be a way out of this by addressing this issue inside the php script:

<?php
    $retorno = (!empty($row['c_return_date'])) ? $row['c_return_date'] : $row['a_return_date'];
    $data = explode('-', $retorno);
    echo date("d/m/Y", mktime(0, 0, 0, $data[1], $data[2] + 1, $data[0]));
?>

I'm currently trying to figure out (actually, more figuring out how does this script works) how to validate this script to, in case of a return date like 0000-00-00 (which means the employee has not come back yet to her activities), not display these sort of output like 12/01/1999.

  • 写回答

3条回答 默认 最新

  • duandanxiu6965 2019-01-18 16:16
    关注

    After all, it was a php script issue.

    <?php
                             $retorno = (!empty($row['c_return_date'])) ? $row['c_return_date'] : $row['a_return_date'];
                             $data = explode('-', $retorn);
                             echo date("d/m/Y", mktime(0, 0, 0, $date[1], $date[2] + 1, $date[0]));
                             ?>
    

    I just needed to put a contitional statement on the script above, to prevent c_return_datefrom displaying anything in case a_return_date is 0000-00-00. Take a look at the if / else clauses:

    <?php
                              if ($row['a_return_date'] != "0000-00-00"){
                                $return = (!empty($row['c_return_date'])) ? $row['c_return_date'] : $row['a_return_date'];
                                $data = explode('-', $return);
                                 echo date("d/m/Y", mktime(0, 0, 0, $date[1], $date[2] + 1, $date[0]));
                                 } else $row['a_return_date_br'] = "-";
                                 ?>
    

    Thank you all. Hope it helps somebody else.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题