【问题标题】:I need to show ADD button if the last_checkup reaches 1 month only如果 last_checkup 仅达到 1 个月,我需要显示添加按钮
【发布时间】:2018-02-23 00:16:52
【问题描述】:

我认为我的查询有问题。我无法获得我想要的正确功能。

示例场景:

如果我今天记录了产前检查,则在接下来的 30 天或一个月后,添加按钮将不会出现。

但是今天加上checkup后这个查询,第二天,add按钮就已经出现了。

这是我的代码:

$dateToday = date('Y-m-d');
$checkPatients = $conn->query("SELECT last_checkup FROM `prenatal_checkup` WHERE  itr_no = '$_GET[id]' limit 1");
$fetchPatients = $checkPatients->fetch_array();
if($fetchPatients['last_checkup'] >= (date('m', strtotime('+1 month')) . '/01/' . date('Y', strtotime('+1 month')))){
    echo '<div class="alert alert-danger" role="alert" style="font-weight: bold; margin-bottom:-13px;"><p>
        '.ucfirst($_GET['firstname'])." ".ucfirst($_GET['lastname']). ' was already estimated her date of confinement.
        Adding new data will be available again after one month. Please click the record below to proceed to next check up.</p></div>';
}
else
{
    ?>
    <button class = "btn btn-primary" id = "show_com"><i class = "glyphicon glyphicon-plus">ADD</i></button>
    <?php
}

【问题讨论】:

  • 请注意,您的查询不安全,因为您直接向其提供用户提供的数据 ($_GET)。请使用占位符实现 mysqli 准备好的语句。您似乎正在进行日期字符串比较,但 m-d-Y 可能无法可靠地作为字符串进行比较。
  • $fetchPatients['edc'] 中有什么
  • @RiggsFolly 这是患者的预计分娩日期
  • 我不完全确定我喜欢你从哪里得到这个:stackoverflow.com/questions/13422032/get-1st-day-of-next-month 但我确实喜欢你在问之前做了研究。考虑到年份翻转,这看起来更可靠:3v4l.org/gMJQu
  • @TechieMickey 我认为 RiggsFolly 要求您确认您的 edc 值也是 m-d-Y 格式。如果没有,我们需要知道它是什么格式。

标签: php


【解决方案1】:

我找到了解决问题的方法。我只是换了

if($fetchPatients['last_checkup'] >= (date('m', strtotime('+1 month')) . '/01/' . date('Y', strtotime('+1 month')))){ 

if (strtotime($fetchPatients['last_checkup']) < strtotime('-30 days'))`

而且效果很好。

【讨论】:

  • 请仅对实际引用的信息使用引用格式,它不应用于突出显示帖子的某些部分。请给您自己的答案打上绿色勾号,以便系统认为此页面已解决。
猜你喜欢
  • 2021-01-28
  • 1970-01-01
  • 1970-01-01
  • 2017-11-04
  • 2014-10-08
  • 1970-01-01
  • 2011-09-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多