日历未正确显示日期

时间:2016-06-24 12:44:13

标签: php ajax codeigniter

我使用setISOdate函数创建了一个日历,循环显示日期并相应地增加日期。虽然我面临的邮件问题是,当我点击下周时,日期开始变得杂乱,并且没有显示下周的正确日期如何才能成功

<div class="calendar">
      <?php if($this->input->get('week') >= 1) { ?>
            <?php
                $page_current = $this->input->get('week') - 1;
            ?>
            <div class="calendar-controls-direction">
                <a href="<?php echo base_url(); ?>reservation?week=<?php echo $page_current; ?>" class="btn-prev">
                    <i class="fa fa-angle-up up-arrow"></i>
                    <span>earlier dates</span>
                </a>
            </div>
        <?php } ?>

        <table class="week-view calendar" border="1" style="border-collapse: collapse" cellpadding="5">
        <?php
            $time_slots = array('08:30', '09:00', '09:30', '10:00', '10:30', '11:00', '11:30', '12:00', '12:30', '13:00', '13:30', '14:00', '14:30', '15:00', '15:30', '16:00', '16:30', '17:00', '17:30', '18:00', '18:30', '19:00');
            $month_slot = array('Jan', 'Feb', 'March' ,'Apr', 'May', 'Jun', 'July', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
            $days_slot  = array('Sunday', 'Monday', 'Tuesday' ,'Wednesday', 'Thursday', 'Friday', 'Saturday');
            $date_slot  = array('1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31');

            $startdate  = $date_slot[0];

            if($month_slot[0] == date('M') || $month_slot[2] == date('M') || $month_slot[4] == date('M') || $month_slot[6] == date('M') || $month_slot[7] == date('M') || $month_slot[9] == date('M') || $month_slot[11] == date('M')) {
                $enddate = $date_slot[30];
            }
            if($month_slot[3] == date('M') || $month_slot[5] == date('M') || $month_slot[8] == date('M') || $month_slot[10] == date('M')) {
                $enddate = $date_slot[29];
            }
            if(date("L") == 1) {
                $enddate = $date_slot[28];
            }
            if(date("L") != 1) {
                $enddate = $date_slot[27];
            }

            $total_days = count($days_slot) - 1;
            $data = $this->db->limit('calendar');
            $data = $this->db->get('calendar');
            for($i = 0; $i <= $total_days; $i++):
        ?>
            <tr>
                <th>
                    <a href="#" class="reserve-toggle js-toggle">
                        <?php
                            $date = new DateTime;
                            if($this->input->get('week') >= 1) {
                                $date->setISODate(date('Y'), $this->input->get('week')*date('m'));
                            } else {
                                $date->setISODate(date('Y'), date('m'), date('d')-7);
                            }
                        ?>
                        <span><?php
                            if(date('N')+$i >= 7) {
                                echo $day = $days_slot[date('N')+$i-7];
                            } else {
                                echo $day = $days_slot[date('N')+$i];
                            }
                                 ?></span>
                        <span>
                        <?php

                            echo $date_slot = $date->format('d') + $i . " " . $date->format('M');
                        ?>

                       </span>
                    </a>
                </th>
                <?php foreach($time_slots as $time): ?>
                <td>
                    <input name="store" type="hidden" value="<?php echo $this->input->get('loc'); ?>">
                    <input type="hidden" name="date_slot<?php echo $i; ?>" value="<?php echo $day . ", " . $date_slot . " " . date('Y'); ?>">
                    <input type="hidden" name="time_slot<?php echo $i; ?>" value="<?php echo $time; ?>" />
                    <input type="hidden" name="val" value="<?php echo $i; ?>" />
                    <input id="slot_<?php echo $time; ?>" onchange="this.form.submit()" type="radio" value="<?php echo $time; ?>">
                    <label for="slot_<?php echo $time; ?>"><?php echo $time; ?></label>
                </form>
                </td>
                <?php endforeach; ?>
                <!--<td class="inactive-slot"><span>Full</span></td>-->
            </tr>
        <?php endfor; ?>
        </table>

        <?php if($this->input->get('week') <= 8) { ?>
            <?php
                $page_current = $this->input->get('week') + 1;
            ?>
            <div class="calendar-controls-direction">
                <a href="<?php echo base_url(); ?>reservation?week=<?php echo $page_current; ?>" class="btn-next">
                    <span>later dates</span>
                    <i class="fa fa-angle-down down-arrow"></i>
                </a>
            </div>
        <?php } ?>
    </div>

请帮助我解决这个问题,因为我已经发布了这个问题很多时间,并且在一个月内没有得到任何回复。

谢谢。

0 个答案:

没有答案