我工作到酒店預訂系統,我目前正試圖選擇可用房間(不保留)。笨 - 選擇其中id不(另一個查詢結果)
Rooms DB Structure:
ID
ROOM NAME
CAPACITY
HOTEL RESERVATIONS DB STRUCTURE:
ID
CHECK_IN
CHECK_OUT
ROOMS
...
這是我當前的代碼:
function searchFreeRooms($data){
$check_in = $data['fields']['check_in'];
$check_out = $data['fields']['check_out'];
$this->db->select("*");
$this->db->from('core_hotel_rooms');
$this->db->where("id NOT IN (select rooms,total_guests from res_hotel where check_in <= '$check_in' AND check_out >= '$check_in' OR check_in <= '$check_out' AND check_out >= '$check_out' OR check_in >= '$check_in' AND check_out <= '$check_out') ");
$query = $this->db->get();
return $query->result();
}
用戶可以預訂多間客房在一個時間,並預留房間ID是存儲在用逗號前分隔欄「房間」:2,3, 5
以我前,室中存在的該列不應該被顯示,但遇到麻煩,因爲被選擇逗號之前僅第一ID(室),例如:2,3,5->僅2被選擇和3,5仍然顯示在我的前面。
問題是在這裏:$this->db->where("id NOT IN (select rooms,total_guests from res_hotel where check_in <= '$check_in' AND check_out >= '$check_in' OR check_in <= '$check_out' AND check_out >= '$check_out' OR check_in >= '$check_in' AND check_out <= '$check_out') ");
我嘗試這樣做:$this->db->where("id NOT IN (1, 2) ");
和它的作品完美,但不上法第二查詢。
對不起,我的英語...
非常感謝所有那些誰可以幫助!
還不行,它選擇逗號之前只有第一ID ... – Idea13