记住 24 小时的复选框设置


Remember checkbox settings for 24 hours

我有一只狗,每天需要吃药3次。

我制作了一个简单的网页,可以从 2 个不同的 iPhone 连接到,并跟踪谁给了他药。

该页面包含 3 个复选框。我怎样才能让他们记住他们是否被选中,以便如果我检查一个,我的妻子打开页面看看我是否完成了,它会显示。

并希望每天在00

:00擦除内存。

解决此任务的最简单方法是什么?

这是我得到的HTML文件:任何人都可以帮助我使用PHP方法吗?

<!DOCTYPE html>
<html>
  <head>
    <title>Medisintime</title>
  </head>
  <body>
    <div style="text-align: center">
      <h1>Medisinetime?</h1>
      <br><br>
      <form action="remember.php" method="post">
        <table style="border: 0; margin-left: auto; margin-right: auto; text-align: left">
            <td>Amaroq Morning:</td>
            <td><input name="am" type="checkbox"></td>
            <td>Amaroq Midday:</td>
            <td><input name="nm" type="checkbox"></td>
            <td>Amaroq Evening:</td>
            <td><input name="ak" type="checkbox"></td>
          </tr>
          <tr>
        </table>
        <br><br>
        <input type="submit" value="Register!">
      </form>
    </div>
  </body>
</html>

而不是表单或数据库 - 为什么不每次用药时将当前时间/日期写入文本文件。当页面加载时 - 打开并回显文件的内容,以便任何好奇的人都可以看到药物记录。

PHP可以很容易地做到这一点。

最好的答案是MySQL数据库,但你也可以用简单的文件来做,比如txt文件或其他东西。如果您有 3 个复选框,则需要 3 个文件。如果你使用 PHP,把这几行放在你的 html 代码之前。

<?php
if(isset($_POST['am'])) {
    file_put_contents('1.txt','');
}
if(isset($_POST['nm'])) {
    file_put_contents('2.txt','');
}
if(isset($_POST['nk'])) {
    file_put_contents('3.txt','');
}
$checked=array(false,false,false);
for($i=1;$i<=3;$i++) {
    if(file_exists("$i.txt")) {
        if(date('Y-m-d',filemtime("$i.txt"))!=date('Y-m-d')) {
            file_delete("$i.txt");
        }
        else {
            $checked[$i-1]=true;
        }
    }
}

您可以稍后在 html 中检查$checked数组的值,例如:

    <td>Amaroq Morning:</td>
        <td><input name="am" type="checkbox" <?php if($checked[0]) { echo 'checked'; } ?>></td>

不是最干净的,但是一个可行的解决方案! :)

在这里我想建议(从技术角度来看)。

1. You have created a form right.
2. Now create a simple table contain id,medicine_1,medicine_2,medicine_3
3. After checking any checkbox save form and load the same page.
4. next time when page loads check if any medicine_1 ==1 OR medicine_2==1 OR medicine_3==1
5.If any value is checked then accordingly checked that checkbox.
6. So this way you can know which medicine is provided.
7. And finally check if time is 00:00 then remove that row.

就是这样。

但就我个人而言,我会建议使用包含帐户的提醒类型的东西,您和您的配偶可以使用相同的帐户并相应地进行更改

另一种解决方案:

饼干和 PHP 会话。

它可以工作。像这样:

如果会话不存在,请使用当前日期和所需时间的值创建新会话。

如果会话确实存在,请比较会话值的时间和当前时间。如果还不是时候,请保留复选框原样。否则,清除该复选框。

似乎很简单。然后,您可以在这两个 if 中添加复选框逻辑。

确保您的会话能够持续 24 小时。这样,如果超过 24 小时,它们就会自动清除。

Mysqlite

防止您使用整个数据库,它基本上与写入文件相同,但:)更好