我正在创建批量预订模块。为此我需要寻找可用的房间,并为预订分配房间。每个房间将通过循环单独添加到预订表。但是会出现此错误消息。
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')
这是控制器:
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');
}
这是我的模特:
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;
}
}
}
}
答案 0 :(得分:1)
错误就像是说的那样,因为你试图将数组用作字符串。
更改
'room_number' => $tmp_rooms
到
'room_number' => $tmp_rooms['room_number']
最好自己调试这样的事情,因为自己解决这个问题后,你会在下次遇到类似的错误时学会如何做到这一点