循环浏览日期并向其添加数据

时间:2018-02-21 01:25:49

标签: php loops date

我想列出2个日期之间的所有日期,在该循环中,我想从我的数据库中插入数据。

就像现在一样,循环列出了相同的日期和时间,但字符串不同。

2018-02-20 23:55   Took 2 pills
2018-02-20 23:55   Refilled with 50 pills
2018-02-20 23:55   Took 2 pills
2018-02-20 23:55   Took 2 pills
2018-02-20 23:55   Took 2 pills
2018-02-20 23:55   Refilled with 40 pills

如果我删除while循环,它看起来像这样:

2018-02-05 18:03   Took 2 pills
2018-02-03 12:37   Refilled with 50 pills
2018-02-02 15:00   Took 2 pills
2018-02-01 13:45   Took 2 pills
2018-01-31 16:34   Took 2 pills
2018-01-31 11:02   Refilled with 40 pills

我希望它列出如下:

2018-02-05 18:03   Took 2 pills
2018-02-04   Took 0 pills
2018-02-03 12:37   Refilled with 50 pills
2018-02-02 15:00   Took 2 pills
2018-02-01 13:45   Took 2 pills
2018-01-31   Took 2 pills at 16:34 and refilled with 40 pills at 11:02

这是循环的样子:

# LOOP
foreach($get_activity AS $activity) {

    # LOOP
    while($date_start != $date_end) {

        # VARIABLE
        $date_start += 86400;


        # ITEMS
        echo '<div>';

            # DATE & TIME
            echo '<div class="datetime">';
                echo datetime($activity['datetime_occured']);
                # echo date('Y-m-d', $date_start);
            echo '</div>';


            # ACTIVITY
            echo '<div class="string">';

                # IF
                if($activity['data_pills_taken'] != 0) {
                    echo 'Tog <span>'.$activity['data_pills_taken'].'</span> tablett'.($activity['data_pills_taken'] == 1 ? '' : 'er');

                # IF
                } elseif($activity['data_pills_total'] != 0) {
                    echo 'Fyllde på med <span>'.$activity['data_pills_total'].'</span> tablett'.($activity['data_pills_total'] == 1 ? '' : 'er');
                }

            echo '</div>';

        echo '</div>';

    }

}

完整源代码:https://gist.github.com/edgren/585d8d1d67c93979003022d8c3cbf5f2

我该如何做到这一点?

0 个答案:

没有答案