-1

I'm creating a bulk booking module. For that I need to look for available rooms, and assign rooms to that reservation. Each room will be added to reservation table individually via a loop. However this error message came instead.

A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: mysql/mysql_driver.php
Line Number: 552

Error Number: 1054
Unknown column 'Array' in 'field list'
INSERT INTO `reservations` (`guest_id`, `room_type`, `meal_type`, `extra_beds`, `purchases`, `guest_count`, `checkin`, `checkout`, `duration`, `total`, `room_number`, `guest_status`, `payment_status`, `travel_agent`) VALUES ('4', 'Single Room_10000', 'Breakfast_1000', '0_0', 0, '10', '2013-07-16', '2013-07-16', '1', '22250', Array, 'Arrived', 'Pending', '123456789V')

This is Controller:

function assign_available_rooms() {     
    $room_type = $this->input->post('room_type');
    $start_date = $this->input->post('start_date');
    $end_date = $this->input->post('end_date');
    $number_of_rooms = $this->input->post('number_of_rooms');
    $guest_nic_pp_dl = $this->input->post('guest_nic_pp_dl');
    $guest_id['guest_id'] = $this->group_reservations_model->retrieve_guest_id($guest_nic_pp_dl);
    $tmp_rooms['room_number'] = $this->group_reservations_model->get_room_numbers($room_type, $start_date, $end_date, $number_of_rooms);
    $newReservation = array (
        'guest_id' => $guest_id['guest_id'],
        'room_type' => $this->input->post('room_type'),
        'meal_type' => $this->input->post('meal_type'),
        'extra_beds' => $this->input->post('ext_beds'),
        'purchases' => 0,
        'guest_count' => $this->input->post('number_of_guests'),
        'checkin' => $this->input->post('start_date'),
        'checkout' => $this->input->post('end_date'),
        'duration' => $this->input->post('reservation_duration'),
        'total' => $this->input->post('total'),
        'room_number' => $tmp_rooms,
        'guest_status' => $this->input->post('guest_status'),
        'payment_status' => 'Pending',
        'travel_agent' => $this->input->post('guest_nic_pp_dl')
        );
    $this->group_reservations_model->assign_rooms($room_type, $start_date, $end_date, $number_of_rooms, $newReservation, $guest_id);
    $this->load->view('success');

}

This is my Model:

function assign_rooms($room_type, $start_date, $end_date, $number_of_rooms, $newReservation, $guest_id, $tmpRoomNumber = array()) {

    $query = $this->db->query(
        "SELECT a.room_number
        FROM rooms a LEFT OUTER JOIN (  SELECT room_number
                                        FROM reservations
                                        WHERE checkin >= '$start_date'
                                        OR checkout <= '$end_date'
                                        ) b
        ON a.room_number = b.room_number
        WHERE b.room_number is NULL
        AND a.room_type = SUBSTRING_INDEX('$room_type', '_', '1')
        AND a.housekeeping_status = 'Clean'
        ORDER BY a.room_number ASC
        LIMIT $number_of_rooms ");

    if($query->num_rows()>0) {
        foreach($query->result_array() as $row) {
            $this->db->trans_begin();
            $this->db->insert('reservations', $newReservation, $guest_id);

            if ($this->db->trans_status() === FALSE) {
                $this->db->trans_rollback();
                return false;
            }
            else {
                $this->db->trans_commit();
            return true;
            }
        }
    }       

}
4

1 回答 1

1

就像所说的那样,由于您试图将数组用作字符串而发生错误。

改变

'room_number' => $tmp_rooms

'room_number' => $tmp_rooms['room_number']

自己调试这样的事情是个好主意,因为通过自己解决问题,您将学习如何在下次遇到类似错误时进行操作

于 2013-07-16T11:51:12.797 回答