PHP日历中的回声日期间隔

时间:2018-06-06 11:10:46

标签: php dateinterval

我正在创建一个日历,我迫切需要一个解决方案。数据库中有信息记录,代码读取这些记录。两列包含date fromdate to。我必须输出以不同颜色出现在数据库中的这些日期。我已多次尝试过。问题是代码输出它可以在数据库中获取的最后一条记录或所有日期时段,但是这些时段会根据数据库中有多少行而重复。Here is the output I get

<div id="calender_section_top">
            <ul>
                <li>Mon</li>
                <li>Tue</li>
                <li>Wed</li>
                <li>Thu</li>
                <li>Fri</li>
                <li>Sat</li>
                <li>Sun</li>
            </ul>
        </div>
        <div id="calender_section_bot">
            <ul>
            <?php
$dateYear = ($year != '') ? $year : date("Y");
$dateMonth = ($month != '') ? $month : date("m");
$date = $dateYear . '-' . $dateMonth . '-01';
$currentMonthFirstDay = date("N", strtotime($date));
$totalDaysOfMonth = cal_days_in_month(CAL_GREGORIAN, $dateMonth, $dateYear);
$totalDaysOfMonthDisplay = ($currentMonthFirstDay == 7) ? ($totalDaysOfMonth) : ($totalDaysOfMonth + $currentMonthFirstDay);
$boxDisplay = ($totalDaysOfMonthDisplay <= 35) ? 35 : 42;
$dayCount = 1;

for ($cb = 1; $cb <= $boxDisplay; $cb++) {
    if (($cb >= $currentMonthFirstDay || $currentMonthFirstDay == 7) && $cb <= ($totalDaysOfMonthDisplay - 1)) {
        $duh = array();
        array_push($duh, $dayCount);

        // Current date

        $currentDate = $dateYear . '-' . $dateMonth . '-' . $dayCount;
        $currentDate = strtotime($currentDate);
        $eventNum = 0;
        $sql = ("SELECT * FROM booking_2 GROUP BY date_from ORDER BY COUNT(book2_id) DESC");
        $result = $this->connect()->query($sql);
        $eventNum = $result->num_rows;
        if ($eventNum > 0) {
            while ($row = $result->fetch_assoc()) {
                $date_from = $row['date_from'];
                $date_to = $row['date_to'];
                $time_from = strtotime($date_from);
                $time_fromm = idate('d', $time_from);
                $time_to = strtotime($date_to);
                $time_too = idate('d', $time_to);
                if ($currentDate >= $time_from && $currentDate <= $time_to) {
                    for ($i = $time_from; $i <= $time_to; $i++) {
                        $cope = array();
                        array_push($cope, $dayCount);
                    }

                    echo '<li id="' . $row['book2_id'] . '" style="background-color:#FF3232 !important;" date="' . date("Y-m-d H:i:s", $currentDate) . '" class="date_cell"><span>' . implode($cope) . '</span>';
                }
            }

            if (!($currentDate >= $time_from && $currentDate <= $time_to)) {
                for ($g = $time_from; $g <= $time_to; $g++) {
                    $duh = array();
                    array_push($duh, $dayCount);
                }

                echo '<li date="' . date("Y-m-d H:i:s", $currentDate) . '" class="date_cell"><span>' . implode($duh) . '</span>';
            }
        }
        else {
            echo '<li date="' . date("Y-m-d H:i:s", $currentDate) . '" class="date_cell"><span>' . implode($duh) . '</span>';
        }

        echo '</li>';
        $dayCount++;
?>
            <?php
    }
    else { ?>
                <li><span>&nbsp;</span></li>
            <?php
    }
} ?>
            </ul>
        </div>
    </div>

抱歉TL; DR。但真的需要帮助。我已经尝试过所有我知道的方法,所以如果你有解决方案,请确保这个有用吗?我认为找到解决方案是一个难题。

0 个答案:

没有答案