codeigniter日历类错误消息

时间:2014-10-01 13:14:03

标签: php sql codeigniter calendar

我使用codeigniter日历类,我正在尝试显示当前月份的所有预订。在这一天的领域,我可能有不止一个结果,我想将它们显示为昏迷分开。

但是,我收到以下错误消息:

A PHP Error was encountered
Severity: Notice
Message: Undefined property: stdClass::$reservationID
Filename: models/reservationcalendarmodel.php
Line Number: 81

A PHP Error was encountered
Severity: Notice
Message: Undefined property: stdClass::$reservationArrivalDate
Filename: models/reservationcalendarmodel.php
Line Number: 81

错误显示10次(我希望数据库中有9条记录)

以下是模型中的(相关)代码:

function getReservations($year,$month) {
    $currentHotelUser = $this->session->userdata('currentHotelUser');
    $query = $this->db->query(
       "SELECT r.*
        FROM room r
        LEFT JOIN (SELECT rr.roomID, re.reservationID,re.reservationArrivalDate 
        FROM reservationroom rr 
        LEFT JOIN reservation re ON re.reservationID = rr.reservationID
        WHERE re.reservationArrivalDate LIKE('".$year."-".$month."-%'))  
        sq ON sq.roomID = r.roomID
        WHERE r.hotelID = ".$currentHotelUser['hotelID']." 
        AND sq.reservationID IS NOT NULL             
    ");

    $cal_data = array();
    foreach($query->result() as $row) {
        // BELLOW IS THE LINE 81 WHERE THE ERROR IS 
        $cal_data[substr($row->reservationArrivalDate,8,2)]= $row->reservationID; 
    }
    return $cal_data;
}    

function generate($year,$month) {
    $cal_data = $this->getReservations($year, $month);
    $this->load->library('calendar', $this->conf);
    return $this->calendar->generate($year,$month,$cal_data);    
} 

以下是来自控制器的(相关)代码:

$this->load->model('ReservationCalendarModel');
$data['calendar'] = $this->ReservationCalendarModel->generate($year,$month);

以下是视图中的(相关)代码:

echo $calendar;

有谁知道为什么我会收到上述错误?

1 个答案:

答案 0 :(得分:2)

问题是您查询的结果没有reservationID和reservationArrivalDate。这就是原因,而循环通过你正在收到此错误。在主选择查询中添加这两列

"SELECT r.*, sq.roomID, sq.reservationId
        FROM room r
        LEFT JOIN (SELECT rr.roomID, re.reservationID,re.reservationArrivalDate 
        FROM reservationroom rr 
        LEFT JOIN reservation re ON re.reservationID = rr.reservationID
        WHERE re.reservationArrivalDate LIKE('".$year."-".$month."-%'))  
        sq ON sq.roomID = r.roomID
        WHERE r.hotelID = ".$currentHotelUser['hotelID']." 
        AND sq.reservationID IS NOT NULL             
    "